mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Created ResetController.
closes #2412 - Updated the reset route to accept token parameter and hand it over to the controller. - Added ResetController which handles the submit action and the button disabled state. - Added reset action to the user model to handle ajax request. - Updated reset template. - Added fixtures to test reset API action. - Fixed password variable names to camel cased style (e.g. newpassword -> newPassword).
This commit is contained in:
parent
6c51b5c2f2
commit
3a72c3ca02
30
ghost/admin/controllers/reset.js
Normal file
30
ghost/admin/controllers/reset.js
Normal file
@ -0,0 +1,30 @@
|
||||
/*global alert, console */
|
||||
var ResetController = Ember.Controller.extend({
|
||||
passwords: {
|
||||
newPassword: '',
|
||||
ne2Password: ''
|
||||
},
|
||||
token: '',
|
||||
submitButtonDisabled: false,
|
||||
actions: {
|
||||
submit: function () {
|
||||
var self = this;
|
||||
this.set('submitButtonDisabled', true);
|
||||
|
||||
this.user.resetPassword(this.passwords, this.token)
|
||||
.then(function () {
|
||||
alert('@TODO Notification : Success');
|
||||
self.transitionToRoute('signin');
|
||||
})
|
||||
.catch(function (response) {
|
||||
alert('@TODO Notification : Failure');
|
||||
console.log(response);
|
||||
})
|
||||
.finally(function () {
|
||||
self.set('submitButtonDisabled', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default ResetController;
|
@ -40,7 +40,7 @@ var SettingsUserController = Ember.Controller.extend({
|
||||
|
||||
password: function () {
|
||||
alert('@TODO: Changing password...');
|
||||
var passwordProperties = this.getProperties('password', 'newpassword', 'ne2password');
|
||||
var passwordProperties = this.getProperties('password', 'newPassword', 'ne2Password');
|
||||
|
||||
if (this.user.validatePassword(passwordProperties).get('passwordIsValid')) {
|
||||
this.user.saveNewPassword(passwordProperties).then(function () {
|
||||
|
@ -42,6 +42,9 @@ var defineFixtures = function (status) {
|
||||
ic.ajax.defineFixture('/ghost/api/v0.1/forgotten/', response({
|
||||
redirect: '/ghost/signin/'
|
||||
}));
|
||||
ic.ajax.defineFixture('/ghost/api/v0.1/reset/', response({
|
||||
msg: 'Password changed successfully'
|
||||
}));
|
||||
};
|
||||
|
||||
export default defineFixtures;
|
@ -3,6 +3,7 @@ import BaseModel from 'ghost/models/base';
|
||||
var UserModel = BaseModel.extend({
|
||||
url: BaseModel.apiRoot + '/users/me/',
|
||||
forgottenUrl: BaseModel.apiRoot + '/forgotten/',
|
||||
resetUrl: BaseModel.apiRoot + '/reset/',
|
||||
|
||||
save: function () {
|
||||
return ic.ajax.request(this.url, {
|
||||
@ -58,11 +59,11 @@ var UserModel = BaseModel.extend({
|
||||
validatePassword: function (password) {
|
||||
var validationErrors = [];
|
||||
|
||||
if (!validator.equals(password.newpassword, password.ne2password)) {
|
||||
if (!validator.equals(password.newPassword, password.ne2Password)) {
|
||||
validationErrors.push("Your new passwords do not match");
|
||||
}
|
||||
|
||||
if (!validator.isLength(password.newpassword, 8)) {
|
||||
if (!validator.isLength(password.newPassword, 8)) {
|
||||
validationErrors.push("Your password is not long enough. It must be at least 8 characters long.");
|
||||
}
|
||||
|
||||
@ -95,6 +96,28 @@ var UserModel = BaseModel.extend({
|
||||
}));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
resetPassword: function (passwords, token) {
|
||||
var self = this;
|
||||
return new Ember.RSVP.Promise(function (resolve, reject) {
|
||||
if (!self.validatePassword(passwords).get('passwordIsValid')) {
|
||||
reject(new Error('Errors found! ' + JSON.stringify(self.get('passwordErrors'))));
|
||||
} else {
|
||||
resolve(ic.ajax.request(self.resetUrl, {
|
||||
type: 'POST',
|
||||
headers: {
|
||||
// @TODO: find a more proper way to do this.
|
||||
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
||||
},
|
||||
data: {
|
||||
newpassword: passwords.newPassword,
|
||||
ne2password: passwords.ne2Password,
|
||||
token: token
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,7 @@ Router.map(function () {
|
||||
this.route('signin');
|
||||
this.route('signup');
|
||||
this.route('forgotten');
|
||||
this.route('reset');
|
||||
this.route('reset', { path: '/reset/:token' });
|
||||
this.resource('posts', { path: '/' }, function () {
|
||||
this.route('post', { path: ':post_id' });
|
||||
});
|
||||
|
@ -1,7 +1,10 @@
|
||||
import styleBody from 'ghost/mixins/style-body';
|
||||
|
||||
var ResetRoute = Ember.Route.extend(styleBody, {
|
||||
classNames: ['ghost-reset']
|
||||
classNames: ['ghost-reset'],
|
||||
setupController: function (controller, params) {
|
||||
controller.token = params.token;
|
||||
}
|
||||
});
|
||||
|
||||
export default ResetRoute;
|
||||
|
@ -1,11 +1,11 @@
|
||||
<section class="reset-box js-reset-box">
|
||||
<form id="reset" class="reset-form" method="post" novalidate="novalidate">
|
||||
<form id="reset" class="reset-form" method="post" novalidate="novalidate" {{action "submit" on="submit"}}>
|
||||
<div class="password-wrap">
|
||||
<input class="password" type="password" placeholder="Password" name="newpassword" />
|
||||
{{input value=passwords.newPassword class="password" type="password" placeholder="Password" name="newpassword" }}
|
||||
</div>
|
||||
<div class="password-wrap">
|
||||
<input class="password" type="password" placeholder="Confirm Password" name="ne2password" />
|
||||
{{input value=passwords.ne2Password class="password" type="password" placeholder="Confirm Password" name="ne2password" }}
|
||||
</div>
|
||||
<button class="button-save" type="submit">Reset Password</button>
|
||||
<button class="button-save" type="submit" {{bind-attr disabled='submitButtonDisabled'}}>Reset Password</button>
|
||||
</form>
|
||||
</section>
|
@ -73,12 +73,12 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label for="user-password-new">New Password</label>
|
||||
{{input value=newpassword type="password" id="user-password-new"}}
|
||||
{{input value=newPassword type="password" id="user-password-new"}}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="user-new-password-verification">Verify Password</label>
|
||||
{{input value=ne2password type="password" id="user-new-password-verification"}}
|
||||
{{input value=ne2Password type="password" id="user-new-password-verification"}}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="button" class="button-delete button-change-password" {{action 'password'}}>Change Password</button>
|
||||
|
Loading…
Reference in New Issue
Block a user