mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
change some socket calls to use the callback, when user changes their email if they are using a gravatar picture it will be updated too, fixed email updating
This commit is contained in:
@@ -195,7 +195,29 @@ var socket,
|
||||
}
|
||||
}
|
||||
|
||||
app.alertSuccess = function(message, timeout) {
|
||||
if(!timeout)
|
||||
timeout = 2000;
|
||||
|
||||
app.alert({
|
||||
title: 'Success',
|
||||
message: message,
|
||||
type: 'success',
|
||||
timeout: timeout
|
||||
});
|
||||
}
|
||||
|
||||
app.alertError = function(message, timeout) {
|
||||
if(!timeout)
|
||||
timeout = 2000;
|
||||
|
||||
app.alert({
|
||||
title: 'Error',
|
||||
message: message,
|
||||
type: 'error',
|
||||
timeout: timeout
|
||||
});
|
||||
}
|
||||
|
||||
app.current_room = null;
|
||||
app.enter_room = function(room) {
|
||||
@@ -254,9 +276,8 @@ var socket,
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
app.showLoginMessage = function() {
|
||||
if(location.href.indexOf('loggedin') !== -1) {
|
||||
function showAlert() {
|
||||
app.alert({
|
||||
type: 'success',
|
||||
title: 'Welcome Back ' + app.username + '!',
|
||||
@@ -264,6 +285,14 @@ var socket,
|
||||
timeout: 5000
|
||||
});
|
||||
}
|
||||
|
||||
if(location.href.indexOf('loggedin') !== -1) {
|
||||
if(document.readyState !== 'complete') {
|
||||
$(document).ready(showAlert);
|
||||
} else {
|
||||
showAlert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jQuery('document').ready(function() {
|
||||
|
||||
@@ -12,23 +12,63 @@
|
||||
postcount.html(app.addCommas(postcount.html()));
|
||||
|
||||
var followBtn = $('#follow-btn');
|
||||
if(yourid === "0") {
|
||||
var unfollowBtn = $('#unfollow-btn');
|
||||
|
||||
if(yourid !== theirid) {
|
||||
if(isFollowing) {
|
||||
followBtn.hide();
|
||||
}
|
||||
else if(yourid !== theirid) {
|
||||
if(isFollowing)
|
||||
followBtn.hide();
|
||||
else
|
||||
unfollowBtn.show();
|
||||
} else {
|
||||
followBtn.show();
|
||||
unfollowBtn.hide();
|
||||
}
|
||||
else {
|
||||
followBtn.hide();
|
||||
}
|
||||
|
||||
followBtn.on('click', function() {
|
||||
socket.emit('api:user.follow', {uid: theirid}, function(success) {
|
||||
var username = $('.account-username a').html();
|
||||
if(success) {
|
||||
followBtn.hide();
|
||||
unfollowBtn.show();
|
||||
app.alert({
|
||||
title: 'Following',
|
||||
message: 'You are now following ' + username + '!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
} else {
|
||||
app.alert({
|
||||
title: 'Error',
|
||||
message: 'There was an error following' + username + '!',
|
||||
type: 'error',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
followBtn.remove();
|
||||
socket.emit('api:user.follow', {uid: theirid});
|
||||
unfollowBtn.on('click', function() {
|
||||
socket.emit('api:user.unfollow', {uid: theirid}, function(success) {
|
||||
var username = $('.account-username a').html();
|
||||
if(success) {
|
||||
followBtn.show();
|
||||
unfollowBtn.hide();
|
||||
app.alert({
|
||||
title: 'Unfollowing',
|
||||
message: 'You are no longer following ' + username + '!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
} else {
|
||||
app.alert({
|
||||
title: 'Error',
|
||||
message: 'There was an error unfollowing' + username + '!',
|
||||
type: 'error',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
@@ -85,7 +85,16 @@ $(document).ready(function() {
|
||||
type: type
|
||||
};
|
||||
|
||||
socket.emit('api:user.changePicture', userData);
|
||||
socket.emit('api:user.changePicture', userData, function(success) {
|
||||
if(!success) {
|
||||
app.alert({
|
||||
title: 'Error',
|
||||
message: 'There was an error changing picture!',
|
||||
type: 'error',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var selectedImageType = '';
|
||||
@@ -102,7 +111,21 @@ $(document).ready(function() {
|
||||
signature:$('#inputSignature').val()
|
||||
};
|
||||
|
||||
socket.emit('api:user.updateProfile', userData);
|
||||
socket.emit('api:user.updateProfile', userData, function(data) {
|
||||
if(data.success) {
|
||||
app.alertSuccess('Your profile has been updated successfully!');
|
||||
if(data.picture) {
|
||||
$('#user-current-picture').attr('src', data.picture);
|
||||
$('#user_label img').attr('src', data.picture);
|
||||
}
|
||||
if(data.gravatarpicture) {
|
||||
$('#user-gravatar-picture').attr('src', data.gravatarpicture);
|
||||
gravatarPicture = data.gravatarpicture;
|
||||
}
|
||||
} else {
|
||||
app.alertError('There was an error updating your profile!');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -231,16 +254,10 @@ $(document).ready(function() {
|
||||
password_confirm.on('keyup', onPasswordConfirmChanged);
|
||||
|
||||
$('#changePasswordBtn').on('click', function() {
|
||||
if(passwordvalid && passwordsmatch && currentPassword.val()) {
|
||||
socket.emit('api:user.changePassword', {
|
||||
'currentPassword': currentPassword.val(),
|
||||
'newPassword': password.val()
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
socket.on('api:user.changePassword', function(data) {
|
||||
if(passwordvalid && passwordsmatch && currentPassword.val()) {
|
||||
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(data) {
|
||||
|
||||
currentPassword.val('');
|
||||
password.val('');
|
||||
password_confirm.val('');
|
||||
@@ -248,6 +265,17 @@ $(document).ready(function() {
|
||||
password_confirm_notify.html('');
|
||||
passwordsmatch = false;
|
||||
passwordvalid = false;
|
||||
|
||||
if(data.err) {
|
||||
app.alertError(data.err);
|
||||
return;
|
||||
}
|
||||
|
||||
app.alertSuccess('Your password is updated!');
|
||||
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
@@ -9,7 +9,13 @@ $(document).ready(function() {
|
||||
showemail: $('#showemailCheckBox').is(':checked')?1:0
|
||||
};
|
||||
|
||||
socket.emit('api:user.saveSettings', settings);
|
||||
socket.emit('api:user.saveSettings', settings, function(success) {
|
||||
if(success) {
|
||||
app.alertSuccess('Settings saved!');
|
||||
} else {
|
||||
app.alertError('There was an error saving settings!');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
@@ -10,17 +10,34 @@
|
||||
$('#no-following-notice').show();
|
||||
}
|
||||
|
||||
|
||||
if(yourid !== theirid) {
|
||||
$('.unfollow-btn').hide();
|
||||
}
|
||||
else {
|
||||
$('.unfollow-btn').on('click',function() {
|
||||
|
||||
var removeBtn = $(this);
|
||||
var unfollowBtn = $(this);
|
||||
var followingUid = $(this).attr('followingUid');
|
||||
|
||||
removeBtn.parent().remove();
|
||||
socket.emit('api:user.unfollow', {uid: followingUid});
|
||||
socket.emit('api:user.unfollow', {uid: followingUid}, function(success) {
|
||||
var username = unfollowBtn.attr('data-username');
|
||||
if(success) {
|
||||
unfollowBtn.parent().remove();
|
||||
app.alert({
|
||||
title: 'Unfollowing',
|
||||
message: 'You are no longer following ' + username + '!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
} else {
|
||||
app.alert({
|
||||
title: 'Error',
|
||||
message: 'There was an error unfollowing ' + username + '!',
|
||||
type: 'error',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,10 +47,18 @@
|
||||
});
|
||||
|
||||
$('#mark-allread-btn').on('click', function() {
|
||||
socket.emit('api:topics.markAllRead');
|
||||
$(this).remove();
|
||||
var btn = $(this);
|
||||
socket.emit('api:topics.markAllRead', {} , function(success) {
|
||||
if(success) {
|
||||
btn.remove();
|
||||
$('#topics-container').empty();
|
||||
$('#category-no-topics').removeClass('hidden');
|
||||
app.alertSuccess('All topics marked as read!');
|
||||
} else {
|
||||
app.alertError('There was an error marking topics read!');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
@@ -25,7 +25,8 @@
|
||||
<span><i class="icon-circle-blank"></i> <span>offline</span></span>
|
||||
</div>
|
||||
<div id="user-actions">
|
||||
<a id="follow-btn" href="#" class="btn">Follow</a>
|
||||
<a id="follow-btn" href="#" class="btn hide">Follow</a>
|
||||
<a id="unfollow-btn" href="#" class="btn hide">Unfollow</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
<div>
|
||||
<!-- BEGIN following -->
|
||||
|
||||
<div class="users-box">
|
||||
<a href="/users/{following.userslug}">
|
||||
<img src="{following.picture}" class="img-polaroid"/>
|
||||
@@ -34,9 +33,8 @@
|
||||
<span class='postcount'>{following.postcount}</span>
|
||||
<i class='icon-pencil'></i>
|
||||
</div>
|
||||
<a id="unfollow-btn" href="#" class="btn unfollow-btn" followingUid="{following.uid}">Unfollow</a>
|
||||
<a id="unfollow-btn" href="#" class="btn unfollow-btn" followingUid="{following.uid}" data-username="{following.username}">Unfollow</a>
|
||||
</div>
|
||||
|
||||
<!-- END following -->
|
||||
</div>
|
||||
<div id="no-following-notice" class="alert alert-warning hide">This user isn't following anyone :(</div>
|
||||
|
||||
99
src/user.js
99
src/user.js
@@ -185,9 +185,10 @@ var utils = require('./../public/src/utils.js'),
|
||||
});
|
||||
}
|
||||
|
||||
User.updateProfile = function(socket, uid, data) {
|
||||
User.updateProfile = function(uid, data, callback) {
|
||||
|
||||
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
||||
var returnData = {success:false};
|
||||
|
||||
function isSignatureValid(next) {
|
||||
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
||||
@@ -198,14 +199,15 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
|
||||
function isEmailAvailable(next) {
|
||||
if(data['email'] !== undefined) {
|
||||
if(!data['email']) {
|
||||
return next(null, true);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -213,46 +215,53 @@ var utils = require('./../public/src/utils.js'),
|
||||
} 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
|
||||
});
|
||||
console.log(err);
|
||||
callback(returnData);
|
||||
} else {
|
||||
updateFields();
|
||||
async.each(fields, updateField, function(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback(returnData);
|
||||
} else {
|
||||
returnData.success = true;
|
||||
callback(returnData);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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]));
|
||||
user.getUserField(uid, 'email', function(email) {
|
||||
RDB.del('email:' + email + ':uid');
|
||||
function updateField(field, callback) {
|
||||
if(data[field] !== undefined) {
|
||||
if(field === 'email') {
|
||||
var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
|
||||
User.setUserField(uid, 'gravatarpicture', gravatarpicture);
|
||||
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(userData) {
|
||||
RDB.del('email:' + userData['email'] + ':uid');
|
||||
RDB.set('email:' + data['email'] + ':uid', uid);
|
||||
User.setUserField(uid, field, data[field]);
|
||||
if(userData.picture !== userData.uploadedpicture) {
|
||||
returnData.picture = gravatarpicture;
|
||||
User.setUserField(uid, 'picture', gravatarpicture);
|
||||
}
|
||||
returnData.gravatarpicture = gravatarpicture;
|
||||
callback(null);
|
||||
});
|
||||
} else if(key === 'signature') {
|
||||
data[key] = utils.strip_tags(data[key]);
|
||||
return;
|
||||
} else if(field === 'signature') {
|
||||
data[field] = utils.strip_tags(data[field]);
|
||||
}
|
||||
|
||||
User.setUserField(uid, key, data[key]);
|
||||
}
|
||||
}
|
||||
User.setUserField(uid, field, data[field]);
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Success',
|
||||
message: 'Your profile has been updated successfully!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(null);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,15 +277,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
});
|
||||
}
|
||||
|
||||
User.changePassword = function(socket, uid, data, callback) {
|
||||
User.changePassword = function(uid, data, callback) {
|
||||
if(!utils.isPasswordValid(data.newPassword)) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Error',
|
||||
message: 'Invalid password!',
|
||||
type: 'error',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(false);
|
||||
callback({err:'Invalid password!'});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -284,7 +287,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
bcrypt.compare(data.currentPassword, user_password, function(err, res) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback(false);
|
||||
callback({err:'bcrpyt compare error!'});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -292,22 +295,10 @@ var utils = require('./../public/src/utils.js'),
|
||||
User.hashPassword(data.newPassword, function(hash) {
|
||||
User.setUserField(uid, 'password', hash);
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Success',
|
||||
message: 'Your password is updated!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(true);
|
||||
callback({err:null});
|
||||
});
|
||||
} else {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Warning',
|
||||
message: 'Your current password is not correct!',
|
||||
type: 'warning',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(false);
|
||||
callback({err:'Your current password is not correct!'});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -247,19 +247,15 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('api:user.isOnline', isUserOnline(uid));
|
||||
});
|
||||
|
||||
socket.on('api:user.changePassword', function(data) {
|
||||
user.changePassword(socket, uid, data, function(success) {
|
||||
if(success) {
|
||||
socket.emit('api:user.changePassword');
|
||||
}
|
||||
});
|
||||
socket.on('api:user.changePassword', function(data, callback) {
|
||||
user.changePassword(uid, data, callback);
|
||||
});
|
||||
|
||||
socket.on('api:user.updateProfile', function(data) {
|
||||
user.updateProfile(socket, uid, data);
|
||||
socket.on('api:user.updateProfile', function(data, callback) {
|
||||
user.updateProfile(uid, data, callback);
|
||||
});
|
||||
|
||||
socket.on('api:user.changePicture', function(data) {
|
||||
socket.on('api:user.changePicture', function(data, callback) {
|
||||
|
||||
var type = data.type;
|
||||
|
||||
@@ -267,6 +263,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
user.getUserFields(uid, ['picture'], function(fields) {
|
||||
fields.uid = uid;
|
||||
socket.emit('api:updateHeader', fields);
|
||||
callback(true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -275,63 +272,34 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
user.setUserField(uid, 'picture', gravatar);
|
||||
updateHeader();
|
||||
});
|
||||
}
|
||||
else if(type === 'uploaded') {
|
||||
} else if(type === 'uploaded') {
|
||||
user.getUserField(uid, 'uploadedpicture', function(uploadedpicture) {
|
||||
user.setUserField(uid, 'picture', uploadedpicture);
|
||||
updateHeader();
|
||||
});
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
socket.on('api:user.follow', function(data) {
|
||||
socket.on('api:user.follow', function(data, callback) {
|
||||
if(uid) {
|
||||
user.follow(uid, data.uid, function(success) {
|
||||
if(success) {
|
||||
user.getUserField(data.uid, 'username', function(username) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Following',
|
||||
message: 'You are now following ' + username + '!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
user.follow(uid, data.uid, callback);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:user.unfollow', function(data) {
|
||||
socket.on('api:user.unfollow', function(data, callback) {
|
||||
if(uid) {
|
||||
user.unfollow(uid, data.uid, function(success) {
|
||||
if(success) {
|
||||
user.getUserField(data.uid, 'username', function(username) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Unfollowed',
|
||||
message: 'You are no longer following ' + username + '!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
user.unfollow(uid, data.uid, callback);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:user.saveSettings', function(data) {
|
||||
socket.on('api:user.saveSettings', function(data, callback) {
|
||||
if(uid) {
|
||||
user.setUserFields(uid, {
|
||||
showemail:data.showemail
|
||||
});
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Saved',
|
||||
message: 'Settings saved!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -339,15 +307,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
topics.post(socket, uid, data.title, data.content, data.category_id, data.images);
|
||||
});
|
||||
|
||||
socket.on('api:topics.markAllRead', function(data) {
|
||||
socket.on('api:topics.markAllRead', function(data, callback) {
|
||||
topics.markAllRead(uid, function(err, success) {
|
||||
if(!err && success) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Success',
|
||||
message: 'All topics marked as read!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user