2018-09-27 22:27:30 +00:00
|
|
|
{% macro auth_login(username, message, is_welcome) %} {# please only use this once per page, it has script shit rn #}
|
|
|
|
{% set is_welcome = is_welcome|default(false) %}
|
|
|
|
|
2018-10-22 17:26:59 +00:00
|
|
|
<form class="container auth" method="post" action="/auth.php">
|
2018-09-27 22:27:30 +00:00
|
|
|
<input type="hidden" name="auth[mode]" value="login">
|
2018-10-02 19:16:42 +00:00
|
|
|
{{ 'login'|csrf|raw }}
|
2018-09-27 22:27:30 +00:00
|
|
|
|
|
|
|
<div class="auth__header">
|
2018-10-22 21:05:22 +00:00
|
|
|
<div class="auth__header__wrapper">
|
|
|
|
<div class="avatar auth__avatar" id="login-avatar"
|
|
|
|
style="background-image:url('/profile.php?u=0&m=avatar');"></div>
|
|
|
|
</div>
|
2018-09-27 22:27:30 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{% if message|length > 0 %}
|
|
|
|
<div class="warning auth__warning{% if is_welcome %} auth__warning--welcome{% endif %}">
|
|
|
|
<div class="warning__content">
|
|
|
|
{{ message }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<div class="auth__form">
|
2018-10-22 17:26:59 +00:00
|
|
|
<input class="input__text auth__input" type="text"
|
2018-09-27 22:27:30 +00:00
|
|
|
name="auth[username]" placeholder="Username" id="login-username"
|
|
|
|
value="{{ username|default('') }}" required>
|
|
|
|
|
2018-10-22 17:26:59 +00:00
|
|
|
<input class="input__text auth__input" type="password"
|
2018-09-27 22:27:30 +00:00
|
|
|
name="auth[password]" placeholder="Password" required>
|
|
|
|
|
2018-10-22 17:26:59 +00:00
|
|
|
<button class="input__button">Login</button>
|
2018-09-27 22:27:30 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
let avatarTimeout = 0;
|
|
|
|
|
|
|
|
function updateLoginAvatar(avatar, username, force) {
|
|
|
|
if (!force) {
|
|
|
|
if (avatarTimeout)
|
|
|
|
return;
|
|
|
|
console.log(avatarTimeout);
|
|
|
|
|
|
|
|
avatarTimeout = setTimeout(() => {
|
|
|
|
updateLoginAvatar(avatar, username, true);
|
|
|
|
clearTimeout(avatarTimeout);
|
|
|
|
avatarTimeout = 0;
|
|
|
|
}, 750);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const request = new XMLHttpRequest;
|
|
|
|
request.addEventListener('readystatechange', () => {
|
|
|
|
if (request.readyState !== 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
avatar.style.backgroundImage = 'url(\'/profile.php?u=%d&m=avatar\')'.replace('%d', request.responseText);
|
|
|
|
});
|
|
|
|
request.open('GET', '/auth.php?m=get_user&u=' + encodeURI(username.value));
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
const avatar = document.getElementById('login-avatar'),
|
|
|
|
username = document.getElementById('login-username');
|
|
|
|
|
|
|
|
updateLoginAvatar(avatar, username, true); // in case there's anything prefilled
|
|
|
|
|
|
|
|
username.addEventListener('keyup', function (ev) {
|
|
|
|
updateLoginAvatar(avatar, username);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{% endmacro %}
|