Merge pull request #674 from Xaekai/channel.registration
Touch up validations on account pages
This commit is contained in:
commit
07c801a12d
|
@ -13,6 +13,7 @@ function merge(locals, res) {
|
||||||
siteTitle: Config.get("html-template.title"),
|
siteTitle: Config.get("html-template.title"),
|
||||||
siteDescription: Config.get("html-template.description"),
|
siteDescription: Config.get("html-template.description"),
|
||||||
siteAuthor: "Calvin 'calzoneman' 'cyzon' Montgomery",
|
siteAuthor: "Calvin 'calzoneman' 'cyzon' Montgomery",
|
||||||
|
domain: res.req.host,
|
||||||
loginDomain: Config.get("https.enabled") ? Config.get("https.full-address")
|
loginDomain: Config.get("https.enabled") ? Config.get("https.full-address")
|
||||||
: Config.get("http.full-address"),
|
: Config.get("http.full-address"),
|
||||||
csrfToken: typeof res.req.csrfToken === 'function' ? res.req.csrfToken() : '',
|
csrfToken: typeof res.req.csrfToken === 'function' ? res.req.csrfToken() : '',
|
||||||
|
|
|
@ -55,9 +55,49 @@ html(lang="en")
|
||||||
input(type="hidden", name="_csrf", value=csrfToken)
|
input(type="hidden", name="_csrf", value=csrfToken)
|
||||||
input(type="hidden", name="action", value="new_channel")
|
input(type="hidden", name="action", value="new_channel")
|
||||||
.form-group
|
.form-group
|
||||||
label.control-label(for="channelname") Channel Name
|
label.control-label(for="channelname") Channel URL
|
||||||
input#channelname.form-control(type="text", name="name")
|
.input-group
|
||||||
button.btn.btn-primary.btn-block(type="submit") Register
|
span.input-group-addon #{domain}/r/
|
||||||
|
input#channelname.form-control(type="text", name="name", maxlength="30", onkeyup="checkChannel()")
|
||||||
|
p#validate_channel.text-danger.pull-right
|
||||||
|
button#register.btn.btn-primary.btn-block(type="submit") Register
|
||||||
|
|
||||||
include footer
|
include footer
|
||||||
+footer()
|
+footer()
|
||||||
|
script( type='text/javascript').
|
||||||
|
function checkChannel(){
|
||||||
|
function nameIsInvalid(id){
|
||||||
|
if(/\s/.test(id)){
|
||||||
|
return 'Channel URL may not contain spaces';
|
||||||
|
}
|
||||||
|
if(id === ''){
|
||||||
|
return 'Channel URL must not be empty';
|
||||||
|
}
|
||||||
|
if(!/^[\w-]{1,30}$/.test(id)){
|
||||||
|
return 'Channel URL may only consist of a-z, A-Z, 0-9, - and _';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var box = $("#channelname");
|
||||||
|
var value = box.val();
|
||||||
|
var lastkey = Date.now();
|
||||||
|
box.data("lastkey", lastkey);
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
if (box.data("lastkey") !== lastkey || box.val() !== value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(nameIsInvalid(value)){
|
||||||
|
$('#validate_channel').text(nameIsInvalid(value))
|
||||||
|
.parent().addClass('has-error').removeClass('has-success');
|
||||||
|
$('#register').addClass('disabled');
|
||||||
|
} else {
|
||||||
|
$('#validate_channel').text('')
|
||||||
|
.parent().addClass('has-success').removeClass('has-error');
|
||||||
|
$('#register').removeClass('disabled');
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,16 +32,20 @@ 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")
|
||||||
|
p#validate_username.text-danger.pull-right
|
||||||
.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()")
|
||||||
|
p#validate_password.text-danger.pull-right
|
||||||
.form-group
|
.form-group
|
||||||
label.control-label(for="password_confirm") Confirm Password
|
label.control-label(for="password_confirm") Confirm Password
|
||||||
input#password_confirm.form-control(type="password", onkeyup="checkPasswords()")
|
input#password_confirm.form-control(type="password", onkeyup="checkPasswords()")
|
||||||
|
p#validate_confirm.text-danger.pull-right
|
||||||
.form-group
|
.form-group
|
||||||
label.control-label(for="email") Email (optional)
|
label.control-label(for="email") Email (optional)
|
||||||
input#email.form-control(type="email", name="email")
|
input#email.form-control(type="email", name="email")
|
||||||
|
p#validate_email.text-danger.pull-right
|
||||||
p
|
p
|
||||||
| Providing an email address is optional and will allow you to recover your account via email if you forget your password.
|
| Providing an email address is optional and will allow you to recover your account via email if you forget your password.
|
||||||
strong If you do not provide an email address, you will not be able to recover a lost account!
|
strong If you do not provide an email address, you will not be able to recover a lost account!
|
||||||
|
@ -62,52 +66,55 @@ html(lang="en")
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
function checkUsername() {
|
function checkUsername() {
|
||||||
var name = $("#username").val();
|
function stateError(text){
|
||||||
$("#usernameerror").remove();
|
target.parent()
|
||||||
|
.addClass("has-error")
|
||||||
|
.removeClass("has-success");
|
||||||
|
$("#validate_username").text(text);
|
||||||
|
}
|
||||||
|
var target = $("#username");
|
||||||
|
var name = target.val();
|
||||||
if (name === "") {
|
if (name === "") {
|
||||||
$("#username").parent().addClass("has-error");
|
stateError('Username must not be empty')
|
||||||
$("<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");
|
stateError("Username must consist of 1-20 characters" +
|
||||||
$("<p/>").addClass("text-danger")
|
" a-Z, A-Z, 0-9, -, or _.");
|
||||||
.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");
|
||||||
|
$("#validate_username").text('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkPasswords() {
|
function checkPasswords() {
|
||||||
var pw = $("#password").val();
|
function stateError(text, target, validator){
|
||||||
var pwc = $("#password_confirm").val();
|
target.parent()
|
||||||
$("#passwordempty").remove();
|
.addClass("has-error")
|
||||||
$("#passwordmismatch").remove();
|
.removeClass("has-success");
|
||||||
|
$(`#${validator}`).text(text);
|
||||||
|
}
|
||||||
|
var target = $("#password");
|
||||||
|
var target2 = $("#password_confirm");
|
||||||
|
var pw = target.val();
|
||||||
|
var pwc = target2.val();
|
||||||
|
|
||||||
|
$("#validate_password").text('');
|
||||||
|
$("#validate_confirm").text('');
|
||||||
if (pw === "") {
|
if (pw === "") {
|
||||||
$("#password").parent().addClass("has-error");
|
stateError('Password must not be empty', target, 'validate_password')
|
||||||
$("<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");
|
stateError('Passwords do not match', target2, 'validate_confirm')
|
||||||
$("<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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue