mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
dont let users with the same username/slug register closes #33
This commit is contained in:
@@ -5,15 +5,18 @@
|
||||
emailEl = document.getElementById('email'),
|
||||
username_notify = document.getElementById('username-notify'),
|
||||
email_notify = document.getElementById('email-notify'),
|
||||
password_notify = document.getElementById('password-notify');
|
||||
password_notify = document.getElementById('password-notify'),
|
||||
emailexists = false,
|
||||
userexists = false;
|
||||
|
||||
username.onkeyup = function() {
|
||||
$(username).on('keyup change', function() {
|
||||
if (username.value.length > 2) socket.emit('user.exists', {username: username.value});
|
||||
else {
|
||||
username_notify.innerHTML = 'Username too short';
|
||||
username_notify.className = 'label label-important';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
emailEl.addEventListener('change', function() {
|
||||
socket.emit('user.email.exists', { email: emailEl.value });
|
||||
}, false);
|
||||
@@ -28,6 +31,7 @@
|
||||
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';
|
||||
@@ -37,6 +41,7 @@
|
||||
}
|
||||
});
|
||||
socket.on('user.email.exists', function(data) {
|
||||
emailexists = data.exists;
|
||||
if (data.exists === true) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
} else {
|
||||
@@ -80,6 +85,14 @@
|
||||
email_notify.innerHTML = '';
|
||||
}
|
||||
|
||||
if(emailexists) {
|
||||
email_notify.innerHTML = 'Email Address exists';
|
||||
validated = false;
|
||||
}
|
||||
|
||||
if(userexists)
|
||||
validated = false;
|
||||
|
||||
return validated;
|
||||
}
|
||||
register.addEventListener('click', function(e) {
|
||||
|
||||
16
src/user.js
16
src/user.js
@@ -163,12 +163,20 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
User.create = function(username, password, email, callback) {
|
||||
|
||||
User.exists(username, function(exists) {
|
||||
var userslug = utils.slugify(username);
|
||||
|
||||
User.exists(userslug, function(exists) {
|
||||
|
||||
if(exists) {
|
||||
console.log("user name taken");
|
||||
callback(null, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
RDB.incr('global:next_user_id', function(err, uid) {
|
||||
RDB.handle(err);
|
||||
|
||||
var gravatar = User.createGravatarURLFromEmail(email);
|
||||
var userslug = utils.slugify(username);
|
||||
|
||||
RDB.hmset('user:'+uid, {
|
||||
'username' : username,
|
||||
@@ -380,8 +388,8 @@ var utils = require('./../public/src/utils.js'),
|
||||
});
|
||||
}
|
||||
|
||||
User.exists = function(username, callback) {
|
||||
User.get_uid_by_username(username, function(exists) {
|
||||
User.exists = function(userslug, callback) {
|
||||
User.get_uid_by_userslug(userslug, function(exists) {
|
||||
exists = !!exists;
|
||||
|
||||
if (callback)
|
||||
|
||||
@@ -147,7 +147,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
|
||||
socket.on('user.exists', function(data) {
|
||||
user.exists(data.username, function(exists){
|
||||
user.exists(utils.slugify(data.username), function(exists){
|
||||
socket.emit('user.exists', {exists: exists});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user