mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Users can change password
Closes #282 * Added a new route * Added new methods * Triple security! * Passwords are actually changed * Also added a change password button, because 'save' has too much baggage. On security: checks whether you're logged in. Then checks whether your old password is actually the one that belongs to you (gets value from the email field for the email, see caveat no2). Checks the new passwords for === and length > 6 on client and server side as well. And THEN changes passwords. Caveats: * didn't add a test, as mocha fails spectacularly on my machine. SQLITE_CORRUPT: database disk image is malformed. Cute, huh? * Because we don't have / I'm not aware of / could not find a "currentuser" variable, I need to get the email address of the user we want to change from the email field. Theoretically if they replace that with another user's email address, and supply their pw, they will change THEIR password instead of their own.
This commit is contained in:
parent
4bc3af4039
commit
54415baf37
@ -69,8 +69,9 @@
|
||||
<label><strong>Verify Password</strong></label>
|
||||
<input type="password" id="user-new-password-verification">
|
||||
</div>
|
||||
<button class="button-change-password">Change Password</button>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
</section>
|
||||
</section>
|
||||
|
@ -176,7 +176,8 @@
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .button-save': 'saveUser'
|
||||
'click .button-save': 'saveUser',
|
||||
'click .button-change-password': 'changePassword'
|
||||
},
|
||||
|
||||
saveUser: function () {
|
||||
@ -194,6 +195,55 @@
|
||||
});
|
||||
},
|
||||
|
||||
changePassword: function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var self = this,
|
||||
email = this.$('#user-email').val(),
|
||||
oldPassword = this.$('#user-password-old').val(),
|
||||
newPassword = this.$('#user-password-new').val(),
|
||||
ne2Password = this.$('#user-new-password-verification').val();
|
||||
|
||||
if (newPassword !== ne2Password || newPassword.length < 6 || oldPassword.length < 6) {
|
||||
this.saveError();
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/ghost/changepw/',
|
||||
type: 'POST',
|
||||
data: {
|
||||
email: email,
|
||||
password: oldPassword,
|
||||
newpassword: newPassword,
|
||||
ne2password: ne2Password
|
||||
},
|
||||
success: function (msg) {
|
||||
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'success',
|
||||
message: msg.msg,
|
||||
status: 'passive',
|
||||
id: 'success-98'
|
||||
}]
|
||||
}));
|
||||
self.$('#user-password-old').val('');
|
||||
self.$('#user-password-new').val('');
|
||||
self.$('#user-new-password-verification').val('');
|
||||
},
|
||||
error: function (obj, string, status) {
|
||||
self.addSubview(new Ghost.Views.NotificationCollection({
|
||||
model: [{
|
||||
type: 'error',
|
||||
message: 'Invalid username or password',
|
||||
status: 'passive'
|
||||
}]
|
||||
}));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
templateName: 'settings/user-profile',
|
||||
|
||||
beforeRender: function () {
|
||||
|
Loading…
Reference in New Issue
Block a user