diff --git a/core/client/controllers/forgotten.js b/core/client/controllers/forgotten.js new file mode 100644 index 0000000000..a8f24aff7f --- /dev/null +++ b/core/client/controllers/forgotten.js @@ -0,0 +1,21 @@ +/*global console, alert */ + +var ForgottenController = Ember.Controller.extend({ + email: '', + actions: { + submit: function () { + var self = this; + self.user.fetchForgottenPasswordFor(this.email) + .then(function () { + alert('@TODO Notification: Success'); + self.transitionToRoute('signin'); + }) + .catch(function (response) { + alert('@TODO'); + console.log(response); + }); + } + } +}); + +export default ForgottenController; diff --git a/core/client/fixtures/init.js b/core/client/fixtures/init.js index 812858213a..24c4d6b0a8 100644 --- a/core/client/fixtures/init.js +++ b/core/client/fixtures/init.js @@ -39,6 +39,9 @@ var defineFixtures = function (status) { ic.ajax.defineFixture('/ghost/changepw/', response({ msg: 'Password changed successfully' })); + ic.ajax.defineFixture('/ghost/api/v0.1/forgotten/', response({ + redirect: '/ghost/signin/' + })); }; export default defineFixtures; \ No newline at end of file diff --git a/core/client/models/user.js b/core/client/models/user.js index 8a21b9f04b..1ccb0b49a6 100644 --- a/core/client/models/user.js +++ b/core/client/models/user.js @@ -2,6 +2,7 @@ import BaseModel from 'ghost/models/base'; var UserModel = BaseModel.extend({ url: BaseModel.apiRoot + '/users/me/', + forgottenUrl: BaseModel.apiRoot + '/forgotten/', save: function () { return ic.ajax.request(this.url, { @@ -74,6 +75,26 @@ var UserModel = BaseModel.extend({ this.set('passwordErrors', validationErrors); return this; + }, + + fetchForgottenPasswordFor: function (email) { + var self = this; + return new Ember.RSVP.Promise(function (resolve, reject) { + if (!validator.isEmail(email)) { + reject(new Error('Please enter a correct email address.')); + } else { + resolve(ic.ajax.request(self.forgottenUrl, { + type: 'POST', + headers: { + // @TODO Find a more proper way to do this. + 'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content') + }, + data: { + email: email + } + })); + } + }); } }); diff --git a/core/client/templates/forgotten.hbs b/core/client/templates/forgotten.hbs index 00cefeecba..833db5f620 100644 --- a/core/client/templates/forgotten.hbs +++ b/core/client/templates/forgotten.hbs @@ -1,8 +1,8 @@
-
+
-
\ No newline at end of file +