981fcb11dbf5bd4528e0dd76288e9e8c3ef8eb28
[blerg.git] / www / jssrc / blerg / AccountCenter.js
1 enyo.kind({
2     name: "blerg.AccountCenter",
3     statics: {
4         locationDetect: function(l) {
5             var m = l.hash.match(/^#\/account$/);
6             if (m) {
7                 return {
8                     kind: 'blerg.AccountCenter'
9                 };
10             }
11         }
12     },
13     handlers: {
14         onLogin: "loginStatusChange",
15         onLogout: "loginStatusChange"
16     },
17     components: [
18         {name: 'accountCenterContent', showing: false, components: [
19             {tag: 'h2', content: "Change Password"},
20             {kind: "blerg.PasswdForm"},
21             {tag: 'h2', content: "Email"},
22             {kind: 'blerg.EmailForm'},
23             {tag: 'h2', content: "Generate recovery link"},
24             {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},
25             {tag: 'form', onsubmit: 'generateRecoveryLink', components: [
26                 {kind: 'onyx.InputDecorator', classes: "recovery", components: [
27                     {kind: 'onyx.Input', name: "recoveryVerifier"}
28                 ]},
29                 {kind: 'onyx.Button', content: "Generate", classes: "recovery", onclick: "generateRecoveryLink"}
30             ]},
31             {tag: 'p', name: 'recoveryLinkOutput', classes: 'recovery'}
32         ]},
33         {name: 'pleaseLogIn', content: 'Please log in above to use the Account Center.'}
34     ],
35     create: function() {
36         this.inherited(arguments);
37         this.bubble('onSetTitle', {section: 'Account Center'});
38         this.loginStatusChange();
39     },
40     generateRecoveryLink: function(inSender, inEvent) {
41         if (this.$.recoveryVerifier.getValue() != 'blërg') {
42             this.$.recoveryLinkOutput.setContent('Please read the text above');
43             return;
44         }
45
46         var req = new enyo.Ajax({
47             url: '/aux/recovery/new',
48             handleAs: 'text'
49         });
50
51         req.response(this, function(inSender, inResponse) {
52             this.$.recoveryLinkOutput.setContent(inResponse);
53         });
54
55         req.error(this, function(inSender, inResponse) {
56             this.$.recoveryLinkOutput.setContent('Failed: ' + req.xhrResponse.status);
57         });
58
59         req.go();
60     },
61     loginStatusChange: function(inSender, inEvent) {
62         this.$.pleaseLogIn.setShowing(!blerg.API.loggedIn);
63         this.$.accountCenterContent.setShowing(blerg.API.loggedIn);
64     }
65 });