diff --git a/core/client/controllers/reset.js b/core/client/controllers/reset.js
new file mode 100644
index 0000000000..13e3ba4473
--- /dev/null
+++ b/core/client/controllers/reset.js
@@ -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;
diff --git a/core/client/controllers/settings/user.js b/core/client/controllers/settings/user.js
index f53900f337..1ba9eaebce 100644
--- a/core/client/controllers/settings/user.js
+++ b/core/client/controllers/settings/user.js
@@ -32,7 +32,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 () {
diff --git a/core/client/fixtures/init.js b/core/client/fixtures/init.js
index 24c4d6b0a8..a603924f52 100644
--- a/core/client/fixtures/init.js
+++ b/core/client/fixtures/init.js
@@ -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;
\ No newline at end of file
diff --git a/core/client/models/user.js b/core/client/models/user.js
index 1ccb0b49a6..0da359c914 100644
--- a/core/client/models/user.js
+++ b/core/client/models/user.js
@@ -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
+ }
+ }));
+ }
+ });
}
});
diff --git a/core/client/router.js b/core/client/router.js
index fbddf20f09..11acbbd860 100755
--- a/core/client/router.js
+++ b/core/client/router.js
@@ -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' });
});
diff --git a/core/client/routes/reset.js b/core/client/routes/reset.js
index 8f7b919c08..7aa2b54542 100644
--- a/core/client/routes/reset.js
+++ b/core/client/routes/reset.js
@@ -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;
diff --git a/core/client/templates/reset.hbs b/core/client/templates/reset.hbs
index 186b6d2931..b41c1bdbfb 100644
--- a/core/client/templates/reset.hbs
+++ b/core/client/templates/reset.hbs
@@ -1,11 +1,11 @@