issue #224
parent
f1b4367168
commit
cc55073107
@ -1,157 +1,147 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var username = document.getElementById('username'),
|
var username = $('#username'),
|
||||||
password = document.getElementById('password'),
|
password = $('#password'),
|
||||||
password_confirm = document.getElementById('password-confirm'),
|
password_confirm = $('#password-confirm'),
|
||||||
register = document.getElementById('register'),
|
register = $('#register'),
|
||||||
emailEl = document.getElementById('email'),
|
emailEl = $('#email'),
|
||||||
username_notify = document.getElementById('username-notify'),
|
username_notify = $('#username-notify'),
|
||||||
email_notify = document.getElementById('email-notify'),
|
email_notify = $('#email-notify'),
|
||||||
password_notify = document.getElementById('password-notify'),
|
password_notify = $('#password-notify'),
|
||||||
password_confirm_notify = document.getElementById('password-confirm-notify'),
|
password_confirm_notify = $('#password-confirm-notify'),
|
||||||
usernamevalid = false;
|
validationError = false;
|
||||||
emailexists = false,
|
|
||||||
emailvalid = false,
|
function showError(element, msg) {
|
||||||
userexists = false,
|
element.html(msg);
|
||||||
passwordsmatch = false,
|
element.attr('class', 'alert alert-error');
|
||||||
passwordvalid = false;
|
element.show();
|
||||||
|
validationError = true;
|
||||||
$(username).on('keyup change', function() {
|
}
|
||||||
usernamevalid = utils.isUserNameValid(username.value);
|
|
||||||
|
function showSuccess(element, msg) {
|
||||||
|
element.html(msg);
|
||||||
if(username.value.length < 3) {
|
element.attr('class', 'alert alert-success');
|
||||||
username_notify.innerHTML = 'Username too short';
|
element.show();
|
||||||
username_notify.className = 'label label-important';
|
}
|
||||||
} else if(username.value.length > 13) {
|
|
||||||
username_notify.innerHTML = 'Username too long';
|
function validateEmail() {
|
||||||
username_notify.className = 'label label-important';
|
if(!emailEl.val()) {
|
||||||
} else if(!usernamevalid) {
|
validationError = true;
|
||||||
username_notify.innerHTML = 'Invalid username';
|
email_notify.hide();
|
||||||
username_notify.className = 'label label-important';
|
return;
|
||||||
} else {
|
|
||||||
socket.emit('user.exists', {username: username.value});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!utils.isEmailValid(emailEl.val())) {
|
||||||
|
showError(email_notify, 'Invalid email address.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
socket.emit('user.email.exists', { email: emailEl.val() });
|
||||||
|
}
|
||||||
|
|
||||||
|
emailEl.on('blur', function() {
|
||||||
|
validateEmail();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(emailEl).on('keyup change', function() {
|
function validateUsername() {
|
||||||
emailvalid = utils.isEmailValid(email.value);
|
if(!username.val()) {
|
||||||
|
validationError = true;
|
||||||
|
username_notify.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!emailvalid) {
|
if(username.val().length < config.minimumUsernameLength) {
|
||||||
email_notify.innerHTML = 'Invalid email address';
|
showError(username_notify, 'Username too short!');
|
||||||
email_notify.className = 'label label-important';
|
} else if(username.val().length > config.maximumUsernameLength) {
|
||||||
|
showError(username_notify, 'Username too long!');
|
||||||
|
} else if(!utils.isUserNameValid(username.val())) {
|
||||||
|
showError(username_notify, 'Invalid username!');
|
||||||
|
} else {
|
||||||
|
socket.emit('user.exists', {username: username.val()});
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
socket.emit('user.email.exists', { email: emailEl.value });
|
|
||||||
|
username.on('blur', function() {
|
||||||
|
validateUsername();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(password).on('keyup', function() {
|
function validatePassword() {
|
||||||
passwordvalid = utils.isPasswordValid(password.value);
|
if(!password.val()){
|
||||||
if (password.value.length < 6) {
|
validationError = true;
|
||||||
password_notify.innerHTML = 'Password too short';
|
password_notify.hide();
|
||||||
password_notify.className = 'label label-important';
|
return;
|
||||||
} else if(!passwordvalid) {
|
|
||||||
password_notify.innerHTML = 'Invalid password';
|
|
||||||
password_notify.className = 'label label-important';
|
|
||||||
} else {
|
|
||||||
password_notify.innerHTML = 'OK!';
|
|
||||||
password_notify.className = 'label label-success';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(password.value !== password_confirm.value) {
|
if (password.val().length < config.minimumPasswordLength) {
|
||||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
showError(password_notify, 'Password too short!');
|
||||||
password_confirm_notify.className = 'label label-important';
|
} else if(password.val().length > config.maximumPasswordLength) {
|
||||||
passwordsmatch = false;
|
showError(password_notify, 'Password too long!');
|
||||||
|
} else if(!utils.isPasswordValid(password.val())) {
|
||||||
|
showError(password_notify, 'Invalid password!');
|
||||||
|
} else {
|
||||||
|
showSuccess(password_notify, 'OK!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(password.val() !== password_confirm.val() && password_confirm.val() !== '') {
|
||||||
|
showError(password_confirm_notify, 'Passwords must match!');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(password).on('blur', function() {
|
||||||
|
validatePassword();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(password_confirm).on('keyup', function() {
|
function validatePasswordConfirm() {
|
||||||
if(password.value !== password_confirm.value) {
|
if(!password.val() || password_notify.hasClass('alert-error')) {
|
||||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
password_confirm_notify.hide();
|
||||||
password_confirm_notify.className = 'label label-important';
|
return;
|
||||||
passwordsmatch = false;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
password_confirm_notify.innerHTML = 'OK!';
|
if(password.val() !== password_confirm.val()) {
|
||||||
password_confirm_notify.className = 'label label-success';
|
showError(password_confirm_notify, 'Passwords must match!');
|
||||||
passwordsmatch = true;
|
} else {
|
||||||
|
showSuccess(password_confirm_notify, 'OK!');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(password_confirm).on('blur', function() {
|
||||||
|
validatePasswordConfirm();
|
||||||
});
|
});
|
||||||
|
|
||||||
ajaxify.register_events(['user.exists', 'user.email.exists']);
|
ajaxify.register_events(['user.exists', 'user.email.exists']);
|
||||||
|
|
||||||
socket.on('user.exists', function(data) {
|
socket.on('user.exists', function(data) {
|
||||||
userexists = data.exists;
|
|
||||||
if (data.exists === true) {
|
if (data.exists === true) {
|
||||||
username_notify.innerHTML = 'Username exists';
|
showError(username_notify, 'Username already taken!');
|
||||||
username_notify.className = 'label label-important';
|
|
||||||
} else {
|
} else {
|
||||||
username_notify.innerHTML = 'OK!';
|
showSuccess(username_notify, 'OK!');
|
||||||
username_notify.className = 'label label-success';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('user.email.exists', function(data) {
|
socket.on('user.email.exists', function(data) {
|
||||||
emailexists = data.exists;
|
|
||||||
|
|
||||||
if (data.exists === true) {
|
if (data.exists === true) {
|
||||||
email_notify.innerHTML = 'Email Address exists';
|
showError(email_notify, 'Email address already taken!');
|
||||||
email_notify.className = 'label label-important';
|
} else {
|
||||||
}
|
showSuccess(email_notify, 'OK!');
|
||||||
else {
|
|
||||||
email_notify.innerHTML = 'OK!';
|
|
||||||
email_notify.className = 'label label-success';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Alternate Logins
|
// Alternate Logins
|
||||||
var altLoginEl = document.querySelector('.alt-logins');
|
$('.alt-logins li').on('click', function(e) {
|
||||||
altLoginEl.addEventListener('click', function(e) {
|
document.location.href = $(this).attr('data-url');
|
||||||
var target;
|
|
||||||
switch(e.target.nodeName) {
|
|
||||||
case 'LI': target = e.target; break;
|
|
||||||
case 'I': target = e.target.parentNode; break;
|
|
||||||
}
|
|
||||||
if (target) {
|
|
||||||
document.location.href = target.getAttribute('data-url');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function validateForm() {
|
function validateForm() {
|
||||||
var validated = true;
|
validationError = false;
|
||||||
|
|
||||||
if (username.value.length < 2 || !usernamevalid) {
|
|
||||||
username_notify.innerHTML = 'Invalid username';
|
|
||||||
username_notify.className = 'label label-important';
|
|
||||||
validated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password.value.length < 5) {
|
|
||||||
password_notify.innerHTML = 'Password too short';
|
|
||||||
validated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(password.value !== password_confirm.value) {
|
|
||||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!emailvalid) {
|
validateEmail();
|
||||||
email_notify.innerHTML = 'Invalid email address';
|
validateUsername();
|
||||||
validated = false;
|
validatePassword();
|
||||||
}
|
validatePasswordConfirm();
|
||||||
|
|
||||||
if(emailexists) {
|
|
||||||
email_notify.innerHTML = 'Email Address exists';
|
|
||||||
validated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(userexists || !passwordsmatch || !passwordvalid)
|
return validationError;
|
||||||
validated = false;
|
|
||||||
|
|
||||||
return validated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register.addEventListener('click', function(e) {
|
register.on('click', function(e) {
|
||||||
if (!validateForm()) e.preventDefault();
|
if (validateForm()) e.preventDefault();
|
||||||
}, false);
|
});
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
Loading…
Reference in New Issue