merged.. conflicted up the ass. registration looks gud again
commit
bb8f75b4be
@ -1,161 +1,151 @@
|
||||
(function() {
|
||||
var username = document.getElementById('username'),
|
||||
password = document.getElementById('password'),
|
||||
password_confirm = document.getElementById('password-confirm'),
|
||||
register = document.getElementById('register'),
|
||||
emailEl = document.getElementById('email'),
|
||||
username_notify = document.getElementById('username-notify'),
|
||||
email_notify = document.getElementById('email-notify'),
|
||||
password_notify = document.getElementById('password-notify'),
|
||||
password_confirm_notify = document.getElementById('password-confirm-notify'),
|
||||
usernamevalid = false;
|
||||
emailexists = false,
|
||||
emailvalid = false,
|
||||
userexists = false,
|
||||
passwordsmatch = false,
|
||||
passwordvalid = false;
|
||||
|
||||
$(username).on('keyup change', function() {
|
||||
usernamevalid = utils.isUserNameValid(username.value);
|
||||
|
||||
|
||||
if(username.value.length < 3) {
|
||||
username_notify.innerHTML = 'Username too short';
|
||||
username_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
} else if(username.value.length > 13) {
|
||||
username_notify.innerHTML = 'Username too long';
|
||||
username_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
} else if(!usernamevalid) {
|
||||
username_notify.innerHTML = 'Invalid username';
|
||||
username_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
} else {
|
||||
socket.emit('user.exists', {username: username.value});
|
||||
var username = $('#username'),
|
||||
password = $('#password'),
|
||||
password_confirm = $('#password-confirm'),
|
||||
register = $('#register'),
|
||||
emailEl = $('#email'),
|
||||
username_notify = $('#username-notify'),
|
||||
email_notify = $('#email-notify'),
|
||||
password_notify = $('#password-notify'),
|
||||
password_confirm_notify = $('#password-confirm-notify'),
|
||||
validationError = false,
|
||||
successIcon = '<i class="icon icon-ok"></i>';
|
||||
|
||||
function showError(element, msg) {
|
||||
element.html(msg);
|
||||
element.parent().removeClass('alert-success').addClass('alert-danger');
|
||||
element.show();
|
||||
validationError = true;
|
||||
}
|
||||
|
||||
function showSuccess(element, msg) {
|
||||
element.html(msg);
|
||||
element.parent().removeClass('alert-danger').addClass('alert-success');
|
||||
element.show();
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
if(!emailEl.val()) {
|
||||
validationError = true;
|
||||
//email_notify.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
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() {
|
||||
emailvalid = utils.isEmailValid(email.value);
|
||||
function validateUsername() {
|
||||
if(!username.val()) {
|
||||
validationError = true;
|
||||
//username_notify.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!emailvalid) {
|
||||
email_notify.innerHTML = 'Invalid email address';
|
||||
email_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
if(username.val().length < config.minimumUsernameLength) {
|
||||
showError(username_notify, 'Username too short!');
|
||||
} 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('keyup', function() {
|
||||
jQuery('#yourUsername').html(this.value.length > 0 ? this.value : 'username');
|
||||
});
|
||||
|
||||
$(password).on('keyup', function() {
|
||||
passwordvalid = utils.isPasswordValid(password.value);
|
||||
if (password.value.length < 6) {
|
||||
password_notify.innerHTML = 'Password too short';
|
||||
password_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
} else if(!passwordvalid) {
|
||||
password_notify.innerHTML = 'Invalid password';
|
||||
password_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
} else {
|
||||
password_notify.innerHTML = '<i class="icon icon-ok"></i>';
|
||||
password_notify.parentNode.className = 'input-group-addon btn-success label-success';
|
||||
username.on('blur', function() {
|
||||
validateUsername();
|
||||
});
|
||||
|
||||
function validatePassword() {
|
||||
if(!password.val()){
|
||||
validationError = true;
|
||||
//password_notify.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if(password.value !== password_confirm.value && password_confirm.value.length > 0) {
|
||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
||||
password_confirm_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
passwordsmatch = false;
|
||||
} else if (password.value === password_confirm.value && password_confirm.value.length > 0) {
|
||||
password_confirm_notify.innerHTML = '<i class="icon icon-ok"></i>';
|
||||
password_confirm_notify.parentNode.className = 'input-group-addon btn-success label-success';
|
||||
passwordsmatch = true;
|
||||
|
||||
if (password.val().length < config.minimumPasswordLength) {
|
||||
showError(password_notify, 'Password too short!');
|
||||
} else if(password.val().length > config.maximumPasswordLength) {
|
||||
showError(password_notify, 'Password too long!');
|
||||
} else if(!utils.isPasswordValid(password.val())) {
|
||||
showError(password_notify, 'Invalid password!');
|
||||
} else {
|
||||
showSuccess(password_notify, successIcon);
|
||||
}
|
||||
|
||||
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() {
|
||||
if(password.value !== password_confirm.value) {
|
||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
||||
password_confirm_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
passwordsmatch = false;
|
||||
|
||||
function validatePasswordConfirm() {
|
||||
if(!password.val() || password_notify.hasClass('alert-error')) {
|
||||
//password_confirm_notify.hide();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
password_confirm_notify.innerHTML = '<i class="icon icon-ok"></i>';
|
||||
password_confirm_notify.parentNode.className = 'input-group-addon btn-success label-success';
|
||||
passwordsmatch = true;
|
||||
|
||||
if(password.val() !== password_confirm.val()) {
|
||||
showError(password_confirm_notify, 'Passwords must match!');
|
||||
} else {
|
||||
showSuccess(password_confirm_notify, successIcon);
|
||||
}
|
||||
}
|
||||
|
||||
$(password_confirm).on('blur', function() {
|
||||
validatePasswordConfirm();
|
||||
});
|
||||
|
||||
ajaxify.register_events(['user.exists', 'user.email.exists']);
|
||||
|
||||
socket.on('user.exists', function(data) {
|
||||
userexists = data.exists;
|
||||
if (data.exists === true) {
|
||||
username_notify.innerHTML = 'Username exists';
|
||||
username_notify.parentNode.className = 'input-group-addon btn-warning label-warning';
|
||||
showError(username_notify, 'Username already taken!');
|
||||
} else {
|
||||
username_notify.innerHTML = '<i class="icon icon-ok"></i>';
|
||||
username_notify.parentNode.className = 'input-group-addon btn-success label-success';
|
||||
showSuccess(username_notify, successIcon);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('user.email.exists', function(data) {
|
||||
emailexists = data.exists;
|
||||
|
||||
socket.on('user.email.exists', function(data) {
|
||||
if (data.exists === true) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
email_notify.className = 'label label-warning';
|
||||
}
|
||||
else {
|
||||
email_notify.innerHTML = '<i class="icon icon-ok"></i>';
|
||||
email_notify.parentNode.className = 'input-group-addon btn-success label-success';
|
||||
showError(email_notify, 'Email address already taken!');
|
||||
} else {
|
||||
showSuccess(email_notify, successIcon);
|
||||
}
|
||||
});
|
||||
|
||||
// Alternate Logins
|
||||
var altLoginEl = document.querySelector('.alt-logins');
|
||||
altLoginEl.addEventListener('click', function(e) {
|
||||
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');
|
||||
}
|
||||
$('.alt-logins li').on('click', function(e) {
|
||||
document.location.href = $(this).attr('data-url');
|
||||
});
|
||||
|
||||
function validateForm() {
|
||||
var validated = true;
|
||||
|
||||
if (username.value.length < 2 || !usernamevalid) {
|
||||
username_notify.innerHTML = 'Invalid username';
|
||||
username_notify.className = 'label label-warning';
|
||||
validated = false;
|
||||
}
|
||||
validationError = 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!';
|
||||
}
|
||||
validateEmail();
|
||||
validateUsername();
|
||||
validatePassword();
|
||||
validatePasswordConfirm();
|
||||
|
||||
if (!emailvalid) {
|
||||
email_notify.innerHTML = 'Invalid email address';
|
||||
validated = false;
|
||||
}
|
||||
|
||||
if(emailexists) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
validated = false;
|
||||
}
|
||||
return validationError;
|
||||
}
|
||||
|
||||
if(userexists || !passwordsmatch || !passwordvalid)
|
||||
validated = false;
|
||||
register.on('click', function(e) {
|
||||
if (validateForm()) e.preventDefault();
|
||||
});
|
||||
|
||||
return validated;
|
||||
}
|
||||
|
||||
register.addEventListener('click', function(e) {
|
||||
if (!validateForm()) e.preventDefault();
|
||||
}, false);
|
||||
|
||||
}());
|
||||
}());
|
Loading…
Reference in New Issue