more fixes

v1.18.x
Baris Soner Usakli 11 years ago
parent 8740cc0fc7
commit 31d353ab0e

@ -10,37 +10,24 @@ define(function() {
if (inputEl.value.length > 0 && inputEl.value.indexOf('@') !== -1) {
socket.emit('user.reset.send', {
email: inputEl.value
});
} else {
jQuery('#success').hide();
jQuery(errorEl).show();
errorTextEl.innerHTML = 'Please enter a valid email';
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
};
ajaxify.register_events(['user.send_reset']);
socket.on('user.send_reset', function(data) {
var submitEl = document.getElementById('reset');
if (data.status === 'ok') {
jQuery('#error').hide();
jQuery('#success').show();
jQuery('#success p').html('An email has been dispatched to "' + data.email + '" with instructions on setting a new password.');
inputEl.value = '';
});
} else {
jQuery('#success').hide();
jQuery(errorEl).show();
switch (data.message) {
case 'invalid-email':
errorTextEl.innerHTML = 'The email you put in (<span>' + data.email + '</span>) is not registered with us. Please try again.';
break;
case 'send-failed':
errorTextEl.innerHTML = 'There was a problem sending the reset code. Please try again later.';
break;
}
errorTextEl.innerHTML = 'Please enter a valid email';
}
});
};
};
return ResetPassword;

@ -24,6 +24,14 @@ define(function() {
socket.emit('user.reset.commit', {
code: reset_code,
password: password.value
}, function(err) {
if(err) {
return app.alert(err.message);
}
$('#error').hide();
$('#notice').hide();
$('#success').show();
});
}
}, false);
@ -31,26 +39,19 @@ define(function() {
// Enable the form if the code is valid
socket.emit('user.reset.valid', {
code: reset_code
});
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
ajaxify.register_events(['user.reset.valid', 'user.reset.commit']);
socket.on('user.reset.valid', function(data) {
if ( !! data.valid) resetEl.disabled = false;
else {
if ( !! data.valid) {
resetEl.disabled = false;
} else {
var formEl = document.getElementById('reset-form');
// Show error message
$('#error').show();
formEl.parentNode.removeChild(formEl);
}
})
socket.on('user.reset.commit', function(data) {
if (data.status === 'ok') {
$('#error').hide();
$('#notice').hide();
$('#success').show();
}
});
};

@ -30,7 +30,7 @@
<input class="form-control input-lg" type="password" placeholder="A new password" id="password" /><br />
<label for="repeat">[[reset_password:repeat_password]]</label>
<input class="form-control input-lg" type="password" placeholder="The same password" id="repeat" /><br />
<button class="btn btn-primary btn-lg btn-block" id="reset" type="submit" disabled>[[reset_password:reset_password]]</button>
<button class="btn btn-primary btn-lg btn-block" id="reset" type="submit">[[reset_password:reset_password]]</button>
</form>
</div>
<input type="hidden" template-variable="reset_code" value="{reset_code}" />

@ -77,7 +77,7 @@ SocketTopics.markAllRead = function(socket, data, callback) {
return callback(err);
}
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', 0);
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, 0);
callback(null);
});

@ -24,19 +24,19 @@ SocketUser.reset = {};
SocketUser.reset.send = function(socket, data, callback) {
if(data && data.email) {
user.reset.send(socket, data.email);
user.reset.send(socket, data.email, callback);
}
};
SocketUser.reset.valid = function(socket, data, callback) {
if(data && data.code) {
user.reset.validate(socket, data.code);
user.reset.validate(socket, data.code, callback);
}
};
SocketUser.reset.commit = function(socket, data, callback) {
if(data && data.code && data.password) {
user.reset.commit(socket, data.code, data.password);
user.reset.commit(socket, data.code, data.password, callback);
}
};

@ -624,7 +624,7 @@ var async = require('async'),
async.each(uids, function(uid, next) {
Topics.getUnreadTids(uid, 0, 19, function(err, tids) {
websockets.in('uid_' + uid).emit('event:unread.updateCount', tids.length);
websockets.in('uid_' + uid).emit('event:unread.updateCount', null, tids.length);
next();
});
}, function(err) {

@ -770,56 +770,43 @@ var bcrypt = require('bcrypt'),
User.reset = {
validate: function(socket, code, callback) {
if (typeof callback !== 'function') {
callback = null;
}
db.getObjectField('reset:uid', code, function(err, uid) {
if (err) {
return callback(false);
return callback(err);
}
if (uid !== null) {
db.getObjectField('reset:expiry', code, function(err, expiry) {
if (err) {
return callback(false);
return callback(err);
}
if (expiry >= +Date.now() / 1000 | 0) {
if (!callback) {
socket.emit('user:reset.valid', {
valid: true
});
} else {
callback(true);
}
callback(null, true);
} else {
// Expired, delete from db
db.deleteObjectField('reset:uid', code);
db.deleteObjectField('reset:expiry', code);
if (!callback) {
socket.emit('user:reset.valid', {
valid: false
});
} else {
callback(false);
callback(null, false);
}
}
});
} else {
if (!callback) {
socket.emit('user:reset.valid', {
valid: false
});
} else {
callback(false);
}
callback(null, false);
}
});
},
send: function(socket, email) {
send: function(socket, email, callback) {
User.getUidByEmail(email, function(err, uid) {
if (uid !== null) {
if(err) {
return callback(err);
}
if(!uid) {
return callback(new Error('invalid-email'));
} else if(parseInt(uid, 10) !== socket.uid) {
return callback(new Error('invalid-user'));
}
// Generate a new reset code
var reset_code = utils.generateUUID();
db.setObjectField('reset:uid', reset_code, uid);
@ -836,26 +823,19 @@ var bcrypt = require('bcrypt'),
uid: uid
});
socket.emit('user.send_reset', {
status: "ok",
message: "code-sent",
email: email
});
} else {
socket.emit('user.send_reset', {
status: "error",
message: "invalid-email",
email: email
});
}
callback(null);
});
},
commit: function(socket, code, password) {
this.validate(socket, code, function(validated) {
commit: function(socket, code, password, callback) {
this.validate(socket, code, function(err, validated) {
if(err) {
return callback(err);
}
if (validated) {
db.getObjectField('reset:uid', code, function(err, uid) {
if (err) {
return;
return callback(err);
}
User.hashPassword(password, function(err, hash) {
@ -866,9 +846,7 @@ var bcrypt = require('bcrypt'),
db.deleteObjectField('reset:uid', code);
db.deleteObjectField('reset:expiry', code);
socket.emit('user:reset.commit', {
status: 'ok'
});
callback(null);
});
}
});

Loading…
Cancel
Save