Nice is subjective.

This commit is contained in:
Xaekai 2017-06-04 22:04:39 -07:00
parent 8769ca1dd9
commit 668477d711
1 changed files with 35 additions and 28 deletions

View File

@ -32,7 +32,7 @@ html(lang="en")
input(type="hidden", name="_csrf", value=csrfToken) input(type="hidden", name="_csrf", value=csrfToken)
.form-group .form-group
label.control-label(for="username") Username label.control-label(for="username") Username
input#username.form-control(type="text", name="name") input#username.form-control(type="text", name="name", onkeyup="checkUsername()", maxlength="20")
.form-group .form-group
label.control-label(for="password") Password label.control-label(for="password") Password
input#password.form-control(type="password", name="password", onkeyup="checkPasswords()") input#password.form-control(type="password", name="password", onkeyup="checkPasswords()")
@ -62,52 +62,59 @@ html(lang="en")
return valid; return valid;
} }
function checkUsername() { function checkUsername() {
var name = $("#username").val(); function createError(text, target){
target.parent()
.addClass("has-error")
.removeClass("has-success");
$("<p/>").addClass("text-danger")
.attr("id", "usernameerror")
.text(text)
.insertAfter(target);
}
var target = $("#username");
var name = target.val();
$("#usernameerror").remove(); $("#usernameerror").remove();
if (name === "") { if (name === "") {
$("#username").parent().addClass("has-error"); createError('Username must not be empty', target)
$("<p/>").addClass("text-danger")
.attr("id", "usernameerror")
.text("Username must not be empty")
.insertAfter($("#username"));
return false; return false;
} else if (!(/^[-\w\u00c0-\u00ff]{1,20}$/).test(name)) { } else if (!(/^[-\w\u00c0-\u00ff]{1,20}$/).test(name)) {
$("#username").parent().addClass("has-error"); createError("Username must consist of 1-20 characters" +
$("<p/>").addClass("text-danger") " a-Z, A-Z, 0-9, -, or _.", target);
.attr("id", "usernameerror")
.text("Username must consist of 1-20 characters a-Z, A-Z, 0-9 " +
", -, or _.")
.insertAfter($("#username"));
return false; return false;
} else { } else {
$("#username").parent().removeClass("has-error") target.parent().removeClass("has-error")
.addClass("has-success"); .addClass("has-success");
} }
} }
function checkPasswords() { function checkPasswords() {
var pw = $("#password").val(); function createError(text, target, id){
var pwc = $("#password_confirm").val(); target.parent()
.addClass("has-error")
.removeClass("has-success");
$("<p/>").addClass("text-danger")
.attr("id", id)
.text(text)
.insertAfter(target);
}
var target = $("#password");
var target2 = $("#password_confirm");
var pw = target.val();
var pwc = target2.val();
$("#passwordempty").remove(); $("#passwordempty").remove();
$("#passwordmismatch").remove(); $("#passwordmismatch").remove();
if (pw === "") { if (pw === "") {
$("#password").parent().addClass("has-error"); createError('Password must not be empty', target, 'passwordempty')
$("<p/>").addClass("text-danger")
.attr("id", "passwordempty")
.text("Password must not be empty")
.insertAfter($("#password"));
return false; return false;
} else { } else {
$("#password").parent().removeClass("has-error") target.parent().removeClass("has-error")
.addClass("has-success"); .addClass("has-success");
if (pw !== pwc) { if (pw !== pwc) {
$("#password_confirm").parent().addClass("has-error"); createError('Passwords do not match', target2, 'passwordmismatch')
$("<p/>").addClass("text-danger")
.attr("id", "passwordmismatch")
.text("Passwords do not match")
.insertAfter($("#password_confirm"));
return false; return false;
} else { } else {
$("#password_confirm").parent().removeClass("has-error") target2.parent()
.removeClass("has-error")
.addClass("has-success"); .addClass("has-success");
} }
} }