closes #1590, closes #1589

v1.18.x
barisusakli 11 years ago
parent 0dce8647ba
commit 60742ce316

@ -15,8 +15,8 @@ define(function() {
.removeClass('alert-success') .removeClass('alert-success')
.addClass('alert-danger'); .addClass('alert-danger');
element.show(); element.show();
validationError = true;
}); });
validationError = true;
} }
function showSuccess(element, msg) { function showSuccess(element, msg) {
@ -29,7 +29,8 @@ define(function() {
}); });
} }
function validateEmail(email) { function validateEmail(email, callback) {
callback = callback || function() {};
var email_notify = $('#email-notify'); var email_notify = $('#email-notify');
if (!email) { if (!email) {
@ -38,7 +39,7 @@ define(function() {
} }
if (!utils.isEmailValid(email)) { if (!utils.isEmailValid(email)) {
showError(email_notify, 'Invalid email address.'); showError(email_notify, '[[error:invalid-email]]');
return; return;
} }
@ -50,14 +51,18 @@ define(function() {
} }
if (exists) { if (exists) {
showError(email_notify, 'Email address already taken!'); showError(email_notify, '[[error:email-taken]]');
} else { } else {
showSuccess(email_notify, successIcon); showSuccess(email_notify, successIcon);
} }
callback();
}); });
} }
function validateUsername(username) { function validateUsername(username, callback) {
callback = callback || function() {};
var username_notify = $('#username-notify'); var username_notify = $('#username-notify');
if (!username) { if (!username) {
@ -66,11 +71,11 @@ define(function() {
} }
if (username.length < config.minimumUsernameLength) { if (username.length < config.minimumUsernameLength) {
showError(username_notify, 'Username too short!'); showError(username_notify, '[[error:username-too-short]]');
} else if (username.length > config.maximumUsernameLength) { } else if (username.length > config.maximumUsernameLength) {
showError(username_notify, 'Username too long!'); showError(username_notify, '[[error:username-too-long]]');
} else if (!utils.isUserNameValid(username) || !utils.slugify(username)) { } else if (!utils.isUserNameValid(username) || !utils.slugify(username)) {
showError(username_notify, 'Invalid username!'); showError(username_notify, '[[error:invalid-username]]');
} else { } else {
socket.emit('user.exists', { socket.emit('user.exists', {
username: username username: username
@ -80,10 +85,12 @@ define(function() {
} }
if (exists) { if (exists) {
showError(username_notify, 'Username already taken!'); showError(username_notify, '[[error:username-taken]]');
} else { } else {
showSuccess(username_notify, successIcon); showSuccess(username_notify, successIcon);
} }
callback();
}); });
} }
} }
@ -154,22 +161,25 @@ define(function() {
validatePasswordConfirm(password.val(), password_confirm.val()); validatePasswordConfirm(password.val(), password_confirm.val());
}); });
function validateForm() { function validateForm(callback) {
validationError = false; validationError = false;
validateEmail(email.val());
validateUsername(username.val());
validatePassword(password.val(), password_confirm.val()); validatePassword(password.val(), password_confirm.val());
validatePasswordConfirm(password.val(), password_confirm.val()); validatePasswordConfirm(password.val(), password_confirm.val());
return validationError; validateEmail(email.val(), function() {
validateUsername(username.val(), callback);
});
} }
register.on('click', function(e) { register.on('click', function(e) {
if (validateForm()) { var registerBtn = $(this);
e.preventDefault(); e.preventDefault();
validateForm(function() {
if (!validationError) {
registerBtn.parents('form').trigger('submit');
} }
}); });
});
if(agreeTerms.length) { if(agreeTerms.length) {
agreeTerms.on('click', function() { agreeTerms.on('click', function() {

Loading…
Cancel
Save