Make Account Center only usable when logged in
[blerg.git] / www / jssrc / blerg / Recovery.js
1 enyo.kind({
2     name: "blerg.Recovery",
3     components: [
4         {tag: 'h2', content: "Reset Your Password"},
5         {tag: 'form', onsubmit: 'submitRecovery', components: [
6             {kind: 'onyx.InputDecorator', classes: "recovery", components: [
7                 {kind: 'onyx.Input', name: "newPassword", type: 'password'}
8             ]},
9             {kind: 'onyx.Button', content: "Set", onclick: "submitRecovery", classes: "recovery"}
10         ]}
11     ],
12     statics: {
13         locationDetect: function(l) {
14             var m = l.hash.match(/^#\/recovery\//);
15             if (m) {
16                 return {
17                     kind: 'blerg.Recovery'
18                 };
19             }
20         }
21     },
22     create: function() {
23         this.inherited(arguments);
24         this.bubble('onSetTitle', {section: 'Reset Password'});
25     },
26     submitRecovery: function(inSender, inEvent) {
27         var m = location.hash.match(new RegExp('^#/recovery/(.*)$'));
28         if (!m) {
29             alert('Validation failed');
30             return;
31         }
32
33         var req = new enyo.Ajax({
34             url: '/aux/recovery/validate',
35             method: 'POST',
36             postBody: {
37                 data: m[1],
38                 password: this.$.newPassword.getValue()
39             }
40         });
41
42         req.response(this, function(inSender, inResponse) {
43             if (inResponse.status == 'success') {
44                 alert('Password changed successfully');
45                 location = '/';
46             } else {
47                 alert('Password change failed');
48             }
49         });
50
51         req.error(this, function(inSender, inResponse) {
52             alert('Password change failed');
53         });
54
55         req.go();
56     }
57 });