Implement a guest login button, initially hidden

This commit is contained in:
Jeremy Zhang 2018-08-06 03:59:36 +00:00
parent 65576b7ffc
commit 0a88e950d6
3 changed files with 25 additions and 12 deletions

View File

@ -446,6 +446,10 @@ a {
max-width: 100%;
}
#guestlogin_btn {
display: none;
}
#modal_invite_btn {
padding: 0 1em;
}

View File

@ -1489,20 +1489,28 @@
$("#custom_username_field").keyup(function(event){
if (event.keyCode == 13) {
if (!(new RegExp(/^[a-z\d\-_\s]+$/i).test($(this).val()))) {
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
return;
}
if($(this).val().length >= 2 && $(this).val().length <= 32) {
$("#custom_username_field").blur();
if (unauth_captcha_enabled) {
$('#recaptchamodal').modal('open');
} else {
submit_unauthenticated_captcha();
}
}
do_guest_login();
}
});
$("#guestlogin_btn").click(function () {
do_guest_login();
});
function do_guest_login() {
if (!(new RegExp(/^[a-z\d\-_\s]+$/i).test($("#custom_username_field").val()))) {
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
return;
}
if($("#custom_username_field").val().length >= 2 && $("#custom_username_field").val().length <= 32) {
$("#custom_username_field").blur();
if (unauth_captcha_enabled) {
$('#recaptchamodal').modal('open');
} else {
submit_unauthenticated_captcha();
}
}
}
$("#submit-unauthenticated-captcha-btn").click(function(){
lock_login_fields();

View File

@ -149,6 +149,7 @@
<p id="guest_login_instr">{{ _("Of course, you also have the option to login by picking a temporary username for your current browsing session.") }}</p>
<input id="custom_username_field" type="text" {% if session.unauthenticated and session.username %}value="{{ session['username'] }}"{% endif %}>
<label id="custom_username_field_label" class="active" for="custom_username_field">{{ _("Username (Hit ENTER/RETURN key to confirm)") }}</label>
<a id="guestlogin_btn" class="waves-effect waves-light btn-large">Guest Login</a>
</div>
{% endif %}
</div>