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