UNPKG

1.52 kBJavaScriptView Raw
1import Ember from 'ember';
2import ENV from '../config/environment';
3
4var PASSWORD_RESET_URI = ENV.emberAuthenticateMe.passwordResetUri || '/api/password_resets';
5
6export default Ember.ObjectController.extend({
7 password: null,
8 passwordConfirmation: null,
9 error: null,
10
11 checkPassword: function() {
12 var callback = this.get('checkPasswordCallback');
13
14 Ember.run.cancel(callback);
15
16 callback = Ember.run.later(this, function() {
17 var password = this.get('password'),
18 passwordConfirmation = this.get('passwordConfirmation');
19
20 this.set('error', null);
21
22 if (!password) {
23 this.set('error', "Password cannot be blank.");
24 }
25 if (password && password !== passwordConfirmation) {
26 this.set('error', "Passwords must match.");
27 }
28 }, 600);
29
30 this.set('checkPasswordCallback', callback);
31 }.observes('password', 'passwordConfirmation'),
32
33 actions: {
34 reset: function() {
35 var error = this.get('error');
36 var self = this;
37
38 if (!error) {
39 Ember.$.ajax({
40 type: "PUT",
41 url: [PASSWORD_RESET_URI, this.get('token')].join('/'),
42
43 data: {
44 password: this.get('password'),
45 password_confirmation: this.get('password_confirmation')
46 },
47
48 success: function(data){
49 self.transitionTo('/login');
50 },
51
52 error: function(err, text) {
53 self.set('error', 'An unknown error has occurred.');
54 }
55 });
56 }
57 }
58 }
59});