Further refinements for account recovery
[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: "Generate recovery link"},
7         {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},
8         {tag: 'form', onsubmit: 'generateRecoveryLink', components: [
9             {kind: 'onyx.InputDecorator', classes: "recovery", components: [
10                 {kind: 'onyx.Input', name: "recoveryVerifier"}
11             ]},
12             {kind: 'onyx.Button', content: "Generate", classes: "recovery", onclick: "generateRecoveryLink"}
13         ]},
14         {tag: 'p', name: 'recoveryLinkOutput', classes: 'recovery'}
15     ],
16     statics: {
17         locationDetect: function(l) {
18             var m = l.hash.match(/^#\/account$/);
19             if (m) {
20                 return {
21                     kind: 'blerg.AccountCenter'
22                 };
23             }
24         }
25     },
26     create: function() {
27         this.inherited(arguments);
28         this.bubble('onSetTitle', {section: 'Account Center'});
29     },
30     generateRecoveryLink: function(inSender, inEvent) {
31         if (this.$.recoveryVerifier.getValue() != 'blërg') {
32             this.$.recoveryLinkOutput.setContent('Please read the text above');
33             return;
34         }
35
36         var req = new enyo.Ajax({
37             url: '/aux/recovery/new',
38             handleAs: 'text'
39         });
40
41         req.response(this, function(inSender, inResponse) {
42             this.$.recoveryLinkOutput.setContent(inResponse);
43         });
44
45         req.error(this, function(inSender, inResponse) {
46             this.$.recoveryLinkOutput.setContent('Failed: ' + req.xhrResponse.status);
47         });
48
49         req.go();
50     }
51 });