Add new account center and account recovery frontends
[blerg.git] / www / jssrc / blerg / AccountCenter.js
diff --git a/www/jssrc/blerg/AccountCenter.js b/www/jssrc/blerg/AccountCenter.js
new file mode 100644 (file)
index 0000000..80db769
--- /dev/null
@@ -0,0 +1,51 @@
+enyo.kind({
+    name: "blerg.AccountCenter",
+    components: [
+        {tag: 'h2', content: "Change Password"},
+        {kind: "blerg.PasswdForm"},
+        {tag: 'h2', content: "Generate recovery link"},
+        {content: "A recovery link is a URL that will allow you to reset the password on your account. 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},
+        {tag: 'p', components: [
+            {kind: 'onyx.InputDecorator', classes: "recovery", components: [
+                {kind: 'onyx.Input', name: "recoveryVerifier"}
+            ]},
+            {kind: 'onyx.Button', content: "Generate", classes: "recovery", onclick: "generateRecoveryLink"}
+        ]},
+        {tag: 'p', name: 'recoveryLinkOutput', classes: 'recovery'}
+    ],
+    statics: {
+        locationDetect: function(l) {
+            var m = l.hash.match(/^#\/account$/);
+            if (m) {
+                return {
+                    kind: 'blerg.AccountCenter'
+                };
+            }
+        }
+    },
+    create: function() {
+        this.inherited(arguments);
+        this.bubble('onSetTitle', {section: 'Account Center'});
+    },
+    generateRecoveryLink: function(inSender, inEvent) {
+        if (this.$.recoveryVerifier.getValue() != 'blërg') {
+            this.$.recoveryLinkOutput.setContent('Please read the text above');
+            return;
+        }
+
+        var req = new enyo.Ajax({
+            url: '/aux/recovery/new',
+            handleAs: 'text'
+        });
+
+        req.response(this, function(inSender, inResponse) {
+            this.$.recoveryLinkOutput.setContent(inResponse);
+        });
+
+        req.error(this, function(inSender, inResponse) {
+            this.$.recoveryLinkOutput.setContent('Failed: ' + req.xhrResponse.status);
+        });
+
+        req.go();
+    }
+});