Finish validation touchup
This commit is contained in:
parent
d42de93d74
commit
699aa2abe1
|
@ -202,7 +202,6 @@ function handleAccountChannelPage(req, res) {
|
||||||
|
|
||||||
db.channels.listUserChannels(req.user.name, function (err, channels) {
|
db.channels.listUserChannels(req.user.name, function (err, channels) {
|
||||||
sendPug(res, "account-channels", {
|
sendPug(res, "account-channels", {
|
||||||
domain: req.host,
|
|
||||||
channels: channels
|
channels: channels
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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() : '',
|
||||||
|
|
|
@ -56,29 +56,29 @@ html(lang="en")
|
||||||
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 URL
|
label.control-label(for="channelname") Channel URL
|
||||||
span#validation.text-danger.pull-right
|
|
||||||
.input-group
|
.input-group
|
||||||
span.input-group-addon #{domain}/r/
|
span.input-group-addon #{domain}/r/
|
||||||
input#channelname.form-control(type="text", name="name", maxlength="30", onkeyup="checkChannel()")
|
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
|
button#register.btn.btn-primary.btn-block(type="submit") Register
|
||||||
|
|
||||||
include footer
|
include footer
|
||||||
+footer()
|
+footer()
|
||||||
script( type='text/javascript').
|
script( type='text/javascript').
|
||||||
function nameIsInvalid(id){
|
|
||||||
if(/\s/.test(id)){
|
|
||||||
return 'Channel URLs may not contain spaces';
|
|
||||||
}
|
|
||||||
if(id === ''){
|
|
||||||
return 'Channel URLs must not be empty';
|
|
||||||
}
|
|
||||||
if(!/^[\w-]{1,30}$/.test(id)){
|
|
||||||
return 'Channel URLs may only consist of a-z, A-Z, 0-9, - and _';
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkChannel(){
|
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 box = $("#channelname");
|
||||||
var value = box.val();
|
var value = box.val();
|
||||||
var lastkey = Date.now();
|
var lastkey = Date.now();
|
||||||
|
@ -89,11 +89,11 @@ html(lang="en")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(nameIsInvalid(value)){
|
if(nameIsInvalid(value)){
|
||||||
$('#validation').text(nameIsInvalid(value))
|
$('#validate_channel').text(nameIsInvalid(value))
|
||||||
.parent().addClass('has-error').removeClass('has-success');
|
.parent().addClass('has-error').removeClass('has-success');
|
||||||
$('#register').addClass('disabled');
|
$('#register').addClass('disabled');
|
||||||
} else {
|
} else {
|
||||||
$('#validation').text('')
|
$('#validate_channel').text('')
|
||||||
.parent().addClass('has-success').removeClass('has-error');
|
.parent().addClass('has-success').removeClass('has-error');
|
||||||
$('#register').removeClass('disabled');
|
$('#register').removeClass('disabled');
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,19 @@ html(lang="en")
|
||||||
.form-group
|
.form-group
|
||||||
label.control-label(for="username") Username
|
label.control-label(for="username") Username
|
||||||
input#username.form-control(type="text", name="name", onkeyup="checkUsername()", maxlength="20")
|
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,55 +66,51 @@ html(lang="en")
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
function checkUsername() {
|
function checkUsername() {
|
||||||
function createError(text, target){
|
function stateError(text){
|
||||||
target.parent()
|
target.parent()
|
||||||
.addClass("has-error")
|
.addClass("has-error")
|
||||||
.removeClass("has-success");
|
.removeClass("has-success");
|
||||||
$("<p/>").addClass("text-danger")
|
$("#validate_username").text(text);
|
||||||
.attr("id", "usernameerror")
|
|
||||||
.text(text)
|
|
||||||
.insertAfter(target);
|
|
||||||
}
|
}
|
||||||
var target = $("#username");
|
var target = $("#username");
|
||||||
var name = target.val();
|
var name = target.val();
|
||||||
$("#usernameerror").remove();
|
|
||||||
if (name === "") {
|
if (name === "") {
|
||||||
createError('Username must not be empty', target)
|
stateError('Username must not be empty')
|
||||||
return false;
|
return false;
|
||||||
} else if (!(/^[-\w\u00c0-\u00ff]{1,20}$/).test(name)) {
|
} else if (!(/^[-\w\u00c0-\u00ff]{1,20}$/).test(name)) {
|
||||||
createError("Username must consist of 1-20 characters" +
|
stateError("Username must consist of 1-20 characters" +
|
||||||
" a-Z, A-Z, 0-9, -, or _.", target);
|
" a-Z, A-Z, 0-9, -, or _.");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
target.parent().removeClass("has-error")
|
target.parent()
|
||||||
|
.removeClass("has-error")
|
||||||
.addClass("has-success");
|
.addClass("has-success");
|
||||||
|
$("#validate_username").text('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkPasswords() {
|
function checkPasswords() {
|
||||||
function createError(text, target, id){
|
function stateError(text, target, validator){
|
||||||
target.parent()
|
target.parent()
|
||||||
.addClass("has-error")
|
.addClass("has-error")
|
||||||
.removeClass("has-success");
|
.removeClass("has-success");
|
||||||
$("<p/>").addClass("text-danger")
|
$(`#${validator}`).text(text);
|
||||||
.attr("id", id)
|
|
||||||
.text(text)
|
|
||||||
.insertAfter(target);
|
|
||||||
}
|
}
|
||||||
var target = $("#password");
|
var target = $("#password");
|
||||||
var target2 = $("#password_confirm");
|
var target2 = $("#password_confirm");
|
||||||
var pw = target.val();
|
var pw = target.val();
|
||||||
var pwc = target2.val();
|
var pwc = target2.val();
|
||||||
|
|
||||||
$("#passwordempty").remove();
|
$("#validate_password").text('');
|
||||||
$("#passwordmismatch").remove();
|
$("#validate_confirm").text('');
|
||||||
if (pw === "") {
|
if (pw === "") {
|
||||||
createError('Password must not be empty', target, 'passwordempty')
|
stateError('Password must not be empty', target, 'validate_password')
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
target.parent().removeClass("has-error")
|
target.parent()
|
||||||
|
.removeClass("has-error")
|
||||||
.addClass("has-success");
|
.addClass("has-success");
|
||||||
if (pw !== pwc) {
|
if (pw !== pwc) {
|
||||||
createError('Passwords do not match', target2, 'passwordmismatch')
|
stateError('Passwords do not match', target2, 'validate_confirm')
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
target2.parent()
|
target2.parent()
|
||||||
|
|
Loading…
Reference in a new issue