mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +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');
|
||||||
|
|||||||
68
src/user.js
68
src/user.js
@@ -29,6 +29,12 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.isEmailAvailable(email, function(available) {
|
||||||
|
if(!available) {
|
||||||
|
callback(null, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RDB.incr('global:next_user_id', function(err, uid) {
|
RDB.incr('global:next_user_id', function(err, uid) {
|
||||||
RDB.handle(err);
|
RDB.handle(err);
|
||||||
|
|
||||||
@@ -81,6 +87,7 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
callback(null, uid);
|
callback(null, uid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
User.delete = function(uid, callback) {
|
User.delete = function(uid, callback) {
|
||||||
@@ -174,15 +181,50 @@ 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'];
|
||||||
|
|
||||||
|
function isSignatureValid(next) {
|
||||||
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
||||||
callback({error:'Signature can\'t be longer than 150 characters!'});
|
next({error:'Signature can\'t be longer than 150 characters!'}, false);
|
||||||
return;
|
} else {
|
||||||
|
next(null, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEmailAvailable(next) {
|
||||||
|
if(data['email'] !== undefined) {
|
||||||
|
User.getUserField(uid, 'email', function(email) {
|
||||||
|
if(email !== data['email']) {
|
||||||
|
User.isEmailAvailable(data['email'], function(available) {
|
||||||
|
if(!available) {
|
||||||
|
next({error:'Email not available!'}, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next(null, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateFields() {
|
||||||
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
|
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
|
||||||
key = fields[i];
|
key = fields[i];
|
||||||
|
|
||||||
@@ -198,7 +240,25 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({});
|
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) {
|
||||||
|
|||||||
@@ -198,6 +198,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