766e9b2cdc99a78e375f4c0c81368c986cc5769e
[blerg.git] / www / jssrc / blerg / AccountCenter.js
1 enyo.kind({
2     name: "blerg.AccountCenter",
3     components: [
4         {tag: 'h2', content: "Change Password"},
5         {kind: "blerg.PasswdForm"},
6         {tag: 'h2', content: "Email"},
7         {kind: 'blerg.EmailForm'},
8         {tag: 'h2', content: "Generate recovery link"},
9         {content: "A recovery link is a URL that will allow you to reset the password on your account at a later time. Whoever has this link will be able to gain control of your account. This link should be kept in a safe place like an encrypted password manager or a physical piece of paper locked in a safe. The link will expire after one year or the next password change (either via a recovery link or by changing it manually above). To indicate that you understand this, please copy <code>blërg</code> into the textbox below.", tag: 'p', allowHtml: true},
10         {tag: 'form', onsubmit: 'generateRecoveryLink', components: [
11             {kind: 'onyx.InputDecorator', classes: "recovery", components: [
12                 {kind: 'onyx.Input', name: "recoveryVerifier"}
13             ]},
14             {kind: 'onyx.Button', content: "Generate", classes: "recovery", onclick: "generateRecoveryLink"}
15         ]},
16         {tag: 'p', name: 'recoveryLinkOutput', classes: 'recovery'}
17     ],
18     statics: {
19         locationDetect: function(l) {
20             var m = l.hash.match(/^#\/account$/);
21             if (m) {
22                 return {
23                     kind: 'blerg.AccountCenter'
24                 };
25             }
26         }
27     },
28     create: function() {
29         this.inherited(arguments);
30         this.bubble('onSetTitle', {section: 'Account Center'});
31     },
32     generateRecoveryLink: function(inSender, inEvent) {
33         if (this.$.recoveryVerifier.getValue() != 'blërg') {
34             this.$.recoveryLinkOutput.setContent('Please read the text above');
35             return;
36         }
37
38         var req = new enyo.Ajax({
39             url: '/aux/recovery/new',
40             handleAs: 'text'
41         });
42
43         req.response(this, function(inSender, inResponse) {
44             this.$.recoveryLinkOutput.setContent(inResponse);
45         });
46
47         req.error(this, function(inSender, inResponse) {
48             this.$.recoveryLinkOutput.setContent('Failed: ' + req.xhrResponse.status);
49         });
50
51         req.go();
52     }
53 });