mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #70
This commit is contained in:
@@ -149,7 +149,7 @@
|
|||||||
height: 50px;
|
height: 50px;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
margin-left: 1px;
|
margin-left: 1px;
|
||||||
padding: 5px;
|
padding: 5px 5px 5px 0px;
|
||||||
|
|
||||||
li {
|
li {
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
@@ -159,20 +159,15 @@
|
|||||||
}
|
}
|
||||||
p {
|
p {
|
||||||
display: block;
|
display: block;
|
||||||
float: left;
|
padding-left:5px;
|
||||||
width: 70%;
|
|
||||||
margin-left: 10px;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
}
|
}
|
||||||
span {
|
span {
|
||||||
display: block;
|
display: block;
|
||||||
float: left;
|
|
||||||
width: 70%;
|
|
||||||
margin-left: 10px;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
margin-top: -10px;
|
padding-left:5px;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,33 +106,10 @@ $(document).ready(function() {
|
|||||||
website:$('#inputWebsite').val(),
|
website:$('#inputWebsite').val(),
|
||||||
birthday:$('#inputBirthday').val(),
|
birthday:$('#inputBirthday').val(),
|
||||||
location:$('#inputLocation').val(),
|
location:$('#inputLocation').val(),
|
||||||
signature:$('#inputSignature').val(),
|
signature:$('#inputSignature').val()
|
||||||
_csrf:$('#csrf_token').val()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$.post('/users/doedit',
|
socket.emit('api:user.updateProfile', userData);
|
||||||
userData,
|
|
||||||
function(data) {
|
|
||||||
if(data.error) {
|
|
||||||
app.alert({
|
|
||||||
'alert_id': 'user_profile_updated',
|
|
||||||
type: 'error',
|
|
||||||
title: 'Profile Update Error',
|
|
||||||
message: data.error,
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.alert({
|
|
||||||
'alert_id': 'user_profile_updated',
|
|
||||||
type: 'success',
|
|
||||||
title: 'Profile Updated',
|
|
||||||
message: 'Your profile has been updated successfully',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -73,19 +73,6 @@ var user = require('./../user.js'),
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/users/doedit', function(req, res){
|
|
||||||
if(!req.user)
|
|
||||||
return res.redirect('/403');
|
|
||||||
|
|
||||||
if(req.user.uid != req.body.uid) {
|
|
||||||
return res.redirect('/');
|
|
||||||
}
|
|
||||||
|
|
||||||
user.updateProfile(req.user.uid, req.body, function(data) {
|
|
||||||
res.send(data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/users/uploadpicture', function(req, res) {
|
app.post('/users/uploadpicture', function(req, res) {
|
||||||
if(!req.user)
|
if(!req.user)
|
||||||
return res.redirect('/403');
|
return res.redirect('/403');
|
||||||
|
|||||||
184
src/user.js
184
src/user.js
@@ -28,57 +28,64 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
callback(null, 0);
|
callback(null, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RDB.incr('global:next_user_id', function(err, uid) {
|
User.isEmailAvailable(email, function(available) {
|
||||||
RDB.handle(err);
|
if(!available) {
|
||||||
|
callback(null, 0);
|
||||||
var gravatar = User.createGravatarURLFromEmail(email);
|
return;
|
||||||
|
|
||||||
RDB.hmset('user:'+uid, {
|
|
||||||
'uid': uid,
|
|
||||||
'username' : username,
|
|
||||||
'userslug' : userslug,
|
|
||||||
'fullname': '',
|
|
||||||
'location':'',
|
|
||||||
'birthday':'',
|
|
||||||
'website':'',
|
|
||||||
'email' : email,
|
|
||||||
'signature':'',
|
|
||||||
'joindate' : Date.now(),
|
|
||||||
'picture': gravatar,
|
|
||||||
'gravatarpicture' : gravatar,
|
|
||||||
'uploadedpicture': '',
|
|
||||||
'reputation': 0,
|
|
||||||
'postcount': 0,
|
|
||||||
'lastposttime': 0,
|
|
||||||
'administrator': (uid == 1) ? 1 : 0
|
|
||||||
});
|
|
||||||
|
|
||||||
RDB.set('username:' + username + ':uid', uid);
|
|
||||||
RDB.set('email:' + email +':uid', uid);
|
|
||||||
RDB.set('userslug:'+ userslug +':uid', uid);
|
|
||||||
|
|
||||||
if(email) {
|
|
||||||
User.sendConfirmationEmail(email);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RDB.incr('usercount', function(err, count) {
|
RDB.incr('global:next_user_id', function(err, uid) {
|
||||||
RDB.handle(err);
|
RDB.handle(err);
|
||||||
|
|
||||||
io.sockets.emit('user.count', {count: count});
|
var gravatar = User.createGravatarURLFromEmail(email);
|
||||||
});
|
|
||||||
|
|
||||||
RDB.lpush('userlist', uid);
|
RDB.hmset('user:'+uid, {
|
||||||
|
'uid': uid,
|
||||||
io.sockets.emit('user.latest', {userslug: userslug, username: username});
|
'username' : username,
|
||||||
|
'userslug' : userslug,
|
||||||
if (password) {
|
'fullname': '',
|
||||||
User.hashPassword(password, function(hash) {
|
'location':'',
|
||||||
User.setUserField(uid, 'password', hash);
|
'birthday':'',
|
||||||
|
'website':'',
|
||||||
|
'email' : email,
|
||||||
|
'signature':'',
|
||||||
|
'joindate' : Date.now(),
|
||||||
|
'picture': gravatar,
|
||||||
|
'gravatarpicture' : gravatar,
|
||||||
|
'uploadedpicture': '',
|
||||||
|
'reputation': 0,
|
||||||
|
'postcount': 0,
|
||||||
|
'lastposttime': 0,
|
||||||
|
'administrator': (uid == 1) ? 1 : 0
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
RDB.set('username:' + username + ':uid', uid);
|
||||||
|
RDB.set('email:' + email +':uid', uid);
|
||||||
|
RDB.set('userslug:'+ userslug +':uid', uid);
|
||||||
|
|
||||||
callback(null, uid);
|
if(email) {
|
||||||
|
User.sendConfirmationEmail(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
RDB.incr('usercount', function(err, count) {
|
||||||
|
RDB.handle(err);
|
||||||
|
|
||||||
|
io.sockets.emit('user.count', {count: count});
|
||||||
|
});
|
||||||
|
|
||||||
|
RDB.lpush('userlist', uid);
|
||||||
|
|
||||||
|
io.sockets.emit('user.latest', {userslug: userslug, username: username});
|
||||||
|
|
||||||
|
if (password) {
|
||||||
|
User.hashPassword(password, function(hash) {
|
||||||
|
User.setUserField(uid, 'password', hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, uid);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -174,31 +181,84 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.updateProfile = function(uid, data, callback) {
|
User.updateProfile = function(socket, uid, data) {
|
||||||
|
|
||||||
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
||||||
|
|
||||||
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
function isSignatureValid(next) {
|
||||||
callback({error:'Signature can\'t be longer than 150 characters!'});
|
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
||||||
return;
|
next({error:'Signature can\'t be longer than 150 characters!'}, false);
|
||||||
|
} else {
|
||||||
|
next(null, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
|
function isEmailAvailable(next) {
|
||||||
key = fields[i];
|
if(data['email'] !== undefined) {
|
||||||
|
User.getUserField(uid, 'email', function(email) {
|
||||||
if(data[key] !== undefined) {
|
if(email !== data['email']) {
|
||||||
if(key === 'email') {
|
User.isEmailAvailable(data['email'], function(available) {
|
||||||
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
|
if(!available) {
|
||||||
RDB.set('email:' + data['email'] +':uid', uid);
|
next({error:'Email not available!'}, false);
|
||||||
} else if(key === 'signature') {
|
}
|
||||||
data[key] = utils.strip_tags(data[key]);
|
});
|
||||||
}
|
} else {
|
||||||
|
next(null, true);
|
||||||
User.setUserField(uid, key, data[key]);
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next(null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.series([isSignatureValid, isEmailAvailable], function(err, results) {
|
||||||
|
if(err) {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Error',
|
||||||
|
message: err.error,
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
updateFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
callback({});
|
function updateFields() {
|
||||||
|
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
|
||||||
|
key = fields[i];
|
||||||
|
|
||||||
|
if(data[key] !== undefined) {
|
||||||
|
if(key === 'email') {
|
||||||
|
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
|
||||||
|
RDB.set('email:' + data['email'] +':uid', uid);
|
||||||
|
} else if(key === 'signature') {
|
||||||
|
data[key] = utils.strip_tags(data[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
User.setUserField(uid, key, data[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Success',
|
||||||
|
message: 'Your profile has been updated successfully!',
|
||||||
|
type: 'success',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
User.isEmailAvailable = function(email, callback) {
|
||||||
|
RDB.exists('email:' + email + ':uid' , function(err, exists) {
|
||||||
|
if(!err) {
|
||||||
|
callback(exists !== 1);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.changePassword = function(socket, uid, data, callback) {
|
User.changePassword = function(socket, uid, data, callback) {
|
||||||
|
|||||||
@@ -197,6 +197,10 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('api:user.updateProfile', function(data) {
|
||||||
|
user.updateProfile(socket, uid, data);
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('api:topics.post', function(data) {
|
socket.on('api:topics.post', function(data) {
|
||||||
topics.post(socket, uid, data.title, data.content, data.category_id);
|
topics.post(socket, uid, data.title, data.content, data.category_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user