mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
issue #224
This commit is contained in:
@@ -1,157 +1,147 @@
|
||||
(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;
|
||||
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;
|
||||
|
||||
$(username).on('keyup change', function() {
|
||||
usernamevalid = utils.isUserNameValid(username.value);
|
||||
|
||||
|
||||
if(username.value.length < 3) {
|
||||
username_notify.innerHTML = 'Username too short';
|
||||
username_notify.className = 'label label-important';
|
||||
} else if(username.value.length > 13) {
|
||||
username_notify.innerHTML = 'Username too long';
|
||||
username_notify.className = 'label label-important';
|
||||
} else if(!usernamevalid) {
|
||||
username_notify.innerHTML = 'Invalid username';
|
||||
username_notify.className = 'label label-important';
|
||||
} else {
|
||||
socket.emit('user.exists', {username: username.value});
|
||||
function showError(element, msg) {
|
||||
element.html(msg);
|
||||
element.attr('class', 'alert alert-error');
|
||||
element.show();
|
||||
validationError = true;
|
||||
}
|
||||
});
|
||||
|
||||
$(emailEl).on('keyup change', function() {
|
||||
emailvalid = utils.isEmailValid(email.value);
|
||||
function showSuccess(element, msg) {
|
||||
element.html(msg);
|
||||
element.attr('class', 'alert alert-success');
|
||||
element.show();
|
||||
}
|
||||
|
||||
if(!emailvalid) {
|
||||
email_notify.innerHTML = 'Invalid email address';
|
||||
email_notify.className = 'label label-important';
|
||||
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.value });
|
||||
socket.emit('user.email.exists', { email: emailEl.val() });
|
||||
}
|
||||
|
||||
emailEl.on('blur', function() {
|
||||
validateEmail();
|
||||
});
|
||||
|
||||
$(password).on('keyup', function() {
|
||||
passwordvalid = utils.isPasswordValid(password.value);
|
||||
if (password.value.length < 6) {
|
||||
password_notify.innerHTML = 'Password too short';
|
||||
password_notify.className = 'label label-important';
|
||||
} else if(!passwordvalid) {
|
||||
password_notify.innerHTML = 'Invalid password';
|
||||
password_notify.className = 'label label-important';
|
||||
function validateUsername() {
|
||||
if(!username.val()) {
|
||||
validationError = true;
|
||||
username_notify.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
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 {
|
||||
password_notify.innerHTML = 'OK!';
|
||||
password_notify.className = 'label label-success';
|
||||
socket.emit('user.exists', {username: username.val()});
|
||||
}
|
||||
}
|
||||
|
||||
if(password.value !== password_confirm.value) {
|
||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
||||
password_confirm_notify.className = 'label label-important';
|
||||
passwordsmatch = false;
|
||||
}
|
||||
username.on('blur', function() {
|
||||
validateUsername();
|
||||
});
|
||||
|
||||
$(password_confirm).on('keyup', function() {
|
||||
if(password.value !== password_confirm.value) {
|
||||
password_confirm_notify.innerHTML = 'Passwords must match!';
|
||||
password_confirm_notify.className = 'label label-important';
|
||||
passwordsmatch = false;
|
||||
function validatePassword() {
|
||||
if(!password.val()){
|
||||
validationError = true;
|
||||
password_notify.hide();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
password_confirm_notify.innerHTML = 'OK!';
|
||||
password_confirm_notify.className = 'label 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, 'OK!');
|
||||
}
|
||||
|
||||
if(password.val() !== password_confirm.val() && password_confirm.val() !== '') {
|
||||
showError(password_confirm_notify, 'Passwords must match!');
|
||||
}
|
||||
}
|
||||
|
||||
$(password).on('blur', function() {
|
||||
validatePassword();
|
||||
});
|
||||
|
||||
function validatePasswordConfirm() {
|
||||
if(!password.val() || password_notify.hasClass('alert-error')) {
|
||||
password_confirm_notify.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if(password.val() !== password_confirm.val()) {
|
||||
showError(password_confirm_notify, 'Passwords must match!');
|
||||
} else {
|
||||
showSuccess(password_confirm_notify, 'OK!');
|
||||
}
|
||||
}
|
||||
|
||||
$(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.className = 'label label-important';
|
||||
showError(username_notify, 'Username already taken!');
|
||||
} else {
|
||||
username_notify.innerHTML = 'OK!';
|
||||
username_notify.className = 'label label-success';
|
||||
showSuccess(username_notify, 'OK!');
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('user.email.exists', function(data) {
|
||||
emailexists = data.exists;
|
||||
|
||||
if (data.exists === true) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
email_notify.className = 'label label-important';
|
||||
}
|
||||
else {
|
||||
email_notify.innerHTML = 'OK!';
|
||||
email_notify.className = 'label label-success';
|
||||
showError(email_notify, 'Email address already taken!');
|
||||
} else {
|
||||
showSuccess(email_notify, 'OK!');
|
||||
}
|
||||
});
|
||||
|
||||
// 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;
|
||||
validationError = false;
|
||||
|
||||
if (username.value.length < 2 || !usernamevalid) {
|
||||
username_notify.innerHTML = 'Invalid username';
|
||||
username_notify.className = 'label label-important';
|
||||
validated = false;
|
||||
validateEmail();
|
||||
validateUsername();
|
||||
validatePassword();
|
||||
validatePasswordConfirm();
|
||||
|
||||
return validationError;
|
||||
}
|
||||
|
||||
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) {
|
||||
email_notify.innerHTML = 'Invalid email address';
|
||||
validated = false;
|
||||
}
|
||||
|
||||
if(emailexists) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
validated = false;
|
||||
}
|
||||
|
||||
if(userexists || !passwordsmatch || !passwordvalid)
|
||||
validated = false;
|
||||
|
||||
return validated;
|
||||
}
|
||||
|
||||
register.addEventListener('click', function(e) {
|
||||
if (!validateForm()) e.preventDefault();
|
||||
}, false);
|
||||
register.on('click', function(e) {
|
||||
if (validateForm()) e.preventDefault();
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
@@ -91,11 +91,11 @@
|
||||
},
|
||||
|
||||
isUserNameValid: function(name) {
|
||||
return (name && name !== "" && (/^[a-zA-Z0-9 _-]{3,14}$/.test(name)));
|
||||
return (name && name !== "" && (/^[a-zA-Z0-9 _-]+$/.test(name)));
|
||||
},
|
||||
|
||||
isPasswordValid: function(password) {
|
||||
return password && password.indexOf(' ') === -1 && password.length > 5;
|
||||
return password && password.indexOf(' ') === -1;
|
||||
},
|
||||
|
||||
// Blatently stolen from: http://phpjs.org/functions/strip_tags/
|
||||
|
||||
@@ -50,6 +50,14 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form>
|
||||
<h3>User Settings</h3>
|
||||
<div class="alert alert-notify">
|
||||
<strong>Minimum Username Length</strong><br /> <input type="text" class="" value="2" data-field="minimumUsernameLength"><br />
|
||||
<strong>Maximum Username Length</strong><br /> <input type="text" class="" value="16" data-field="maximumUsernameLength"><br />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form>
|
||||
<h3>Post Settings</h3>
|
||||
<div class="alert alert-notify">
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
<h1>Register</h1>
|
||||
<div class="row-fluid">
|
||||
<div class="well {register_window:spansize}">
|
||||
<form method="post" action="{relative_path}/register">
|
||||
<label for="email">Email Address</label><input type="email" name="email" placeholder="Enter Email Address" id="email" /> <span id="email-notify" class="label label-important"></span><br />
|
||||
<label for="username">Username</label><input type="text" name="username" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
|
||||
<label for="password">Password</label><input type="password" name="password" placeholder="Enter Password" id="password" /> <span id="password-notify" class="label label-important"></span> <br />
|
||||
<label for="password-confirm">Confirm Password</label><input type="password" name="password-confirm" placeholder="Confirm Password" id="password-confirm" /> <span id="password-confirm-notify" class="label label-important"></span> <br />
|
||||
<form method="post" action="#">
|
||||
<fieldset>
|
||||
<label for="email"><strong>Email Address</strong></label>
|
||||
<input type="email" name="email" placeholder="Enter Email Address" id="email" autofocus/>
|
||||
<span id="email-notify" class="alert alert-error hide"></span>
|
||||
<span class="help-block">Your email won't be shown to the public unless you want.</span>
|
||||
|
||||
<label for="username"><strong>Username</strong></label>
|
||||
<input type="text" name="username" placeholder="Enter Username" id="username" />
|
||||
<span id="username-notify" class="alert alert-error hide"></span>
|
||||
<span class="help-block">A unique username. {minimumUsernameLength}-{maximumUsernameLength} characters. Others can mention you with @username.</span>
|
||||
|
||||
<label for="password"><strong>Password</strong></label>
|
||||
<input type="password" name="password" placeholder="Enter Password" id="password" />
|
||||
<span id="password-notify" class="alert alert-error hide"></span>
|
||||
<span class="help-block">{minimumPasswordLength}-{maximumPasswordLength} characters.</span>
|
||||
|
||||
<label for="password-confirm"><strong>Confirm Password</strong></label>
|
||||
<input type="password" name="password-confirm" placeholder="Confirm Password" id="password-confirm" />
|
||||
<span id="password-confirm-notify" class="alert alert-error hide"></span>
|
||||
|
||||
<input type="hidden" name="_csrf" value="{token}" />
|
||||
<br/>
|
||||
<button class="btn btn-primary" id="register" type="submit">Register Now</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="well span6 {alternate_logins:display}">
|
||||
|
||||
@@ -88,6 +88,10 @@ var async = require('async'),
|
||||
meta.configs.set('postDelay', 10000);
|
||||
meta.configs.set('minimumPostLength', 8);
|
||||
meta.configs.set('minimumTitleLength', 3);
|
||||
meta.configs.set('minimumUsernameLength', 2);
|
||||
meta.configs.set('maximumUsernameLength', 16);
|
||||
meta.configs.set('minimumPasswordLength', 6);
|
||||
meta.configs.set('maximumPasswordLength', 16);
|
||||
meta.configs.set('imgurClientID', '');
|
||||
|
||||
install.save(server_conf, client_conf, callback);
|
||||
|
||||
@@ -22,6 +22,10 @@ var user = require('./../user.js'),
|
||||
config['minimumTitleLength'] = meta.config['minimumTitleLength'];
|
||||
config['minimumPostLength'] = meta.config['minimumPostLength'];
|
||||
config['imgurClientIDSet'] = !!meta.config['imgurClientID'];
|
||||
config['minimumUsernameLength'] = meta.config['minimumUsernameLength'];
|
||||
config['maximumUsernameLength'] = meta.config['maximumUsernameLength'];
|
||||
config['minimumPasswordLength'] = meta.config['minimumPasswordLength'];
|
||||
config['maximumPasswordLength'] = meta.config['maximumPasswordLength'];
|
||||
|
||||
res.json(200, config);
|
||||
});
|
||||
@@ -97,7 +101,10 @@ var user = require('./../user.js'),
|
||||
}
|
||||
|
||||
data.token = res.locals.csrf_token;
|
||||
|
||||
data.minimumUsernameLength = meta.config['minimumUsernameLength'];
|
||||
data.maximumUsernameLength = meta.config['maximumUsernameLength'];
|
||||
data.minimumPasswordLength = meta.config['minimumPasswordLength'];
|
||||
data.maximumPasswordLength = meta.config['maximumPasswordLength'];
|
||||
res.json(data);
|
||||
});
|
||||
|
||||
|
||||
@@ -217,9 +217,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
|
||||
socket.on('user.exists', function(data) {
|
||||
if(data.username) {
|
||||
user.exists(utils.slugify(data.username), function(exists){
|
||||
socket.emit('user.exists', {exists: exists});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('user.count', function(data) {
|
||||
|
||||
Reference in New Issue
Block a user