Add email verification UI
authorChip Black <bytex64@bytex64.net>
Sun, 1 Mar 2015 18:16:25 +0000 (12:16 -0600)
committerChip Black <bytex64@bytex64.net>
Sun, 1 Mar 2015 18:16:25 +0000 (12:16 -0600)
www/css/blerg.css
www/jssrc/blerg/AccountCenter.js
www/jssrc/blerg/Blerg.js
www/jssrc/blerg/EmailForm.js [new file with mode: 0644]
www/jssrc/blerg/EmailVerify.js [new file with mode: 0644]
www/jssrc/blerg/package.js

index 66add67..4aeca0f 100644 (file)
@@ -554,3 +554,7 @@ footer a {
        color: #333;
        margin-left: 1em;
 }
+
+.email-address {
+    font-weight: bold;
+}
index c3d4667..b32caec 100644 (file)
@@ -3,6 +3,8 @@ enyo.kind({
     components: [
         {tag: 'h2', content: "Change Password"},
         {kind: "blerg.PasswdForm"},
+        {tag: 'h2', content: "Email Notifications"},
+        {kind: 'blerg.EmailForm'},
         {tag: 'h2', content: "Generate recovery link"},
         {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},
         {tag: 'form', onsubmit: 'generateRecoveryLink', components: [
index 755067f..747c0da 100644 (file)
@@ -5,7 +5,7 @@ enyo.kind({
     name: "blerg.Blerg",
     kind: "Control",
     lastHash: null,
-    pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.ExternalURLPost, blerg.Welcome, blerg.AccountCenter, blerg.Recovery ],
+    pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.ExternalURLPost, blerg.Welcome, blerg.AccountCenter, blerg.Recovery, blerg.EmailVerify ],
     handlers: {
         onStartSignup: "showSignupDialog",
         onTryLogin: "tryLogin",
diff --git a/www/jssrc/blerg/EmailForm.js b/www/jssrc/blerg/EmailForm.js
new file mode 100644 (file)
index 0000000..4ee731d
--- /dev/null
@@ -0,0 +1,95 @@
+enyo.kind({
+    name: 'blerg.EmailForm',
+    components: [
+        {name: 'emailRegisterForm', components: [
+            {content: "Enter your email address to get daily digest updates of your feed.", tag: 'p'},
+            {tag: 'form', onsubmit: 'registerEmail', components: [
+                {kind: 'onyx.InputDecorator', classes: 'recovery', components: [
+                    {kind: 'onyx.Input', name: 'email'}
+                ]},
+                {kind: 'onyx.Button', content: 'Register', onclick: 'registerEmail'}
+            ]}
+        ]},
+        {name: 'emailStatus', showing: false, components: [
+            {tag: 'p', components: [
+                {content: 'Registered email: ', tag: null},
+                {name: 'emailOutput', tag: 'span', classes: 'email-address'},
+            ]},
+            {kind: 'onyx.Button', content: 'Deregister', onclick: 'deregisterEmail'}
+        ]},
+        {name: 'emailSent', showing: false, components: [
+            {content: 'An email has been sent to ', tag: null},
+            {name: 'emailSentAddress', tag: 'span', classes: 'email-address'},
+            {content: '.', tag: null}
+        ]}
+
+    ],
+    create: function() {
+        this.inherited(arguments);
+
+        this.fetchEmailStatus();
+    },
+    registerEmail: function(inSender, inEvent) {
+        var email = this.$.email.getValue();
+        this.$.email.setValue('');
+        this.$.email.node.blur();
+
+        var req = new enyo.Ajax({
+            url: '/aux/email/register',
+            method: 'POST',
+            postBody: {
+                email: email
+            }
+        });
+
+        req.response(this, function(inSender, inResponse) {
+            this.$.emailSentAddress.setContent(email);
+            this.$.emailRegisterForm.hide();
+            this.$.emailSent.show();
+        });
+
+        req.error(this, function(inSender, inResponse) {
+            alert('Failed to register email.');
+        });
+
+        req.go();
+    },
+    fetchEmailStatus: function() {
+        var req = new enyo.Ajax({
+            url: '/aux/email/status'
+        });
+
+        req.response(this, function(inSender, inResponse) {
+            if (inResponse.email) {
+                this.$.emailRegisterForm.hide();
+                this.$.emailStatus.show();
+                this.$.emailOutput.setContent(inResponse.email);
+            } else {
+                this.$.emailRegisterForm.show();
+            }
+        });
+
+        req.go();
+    },
+    deregisterEmail: function(inSender, inEvent) {
+        var req = new enyo.Ajax({
+            url: '/aux/email/cancel'
+        });
+
+        req.response(this, function(inSender, inResponse) {
+            if (inResponse.status == 'success') {
+                this.$.emailStatus.hide();
+                this.$.emailRegisterForm.show();
+                alert('Email notifications deregistered');
+            } else {
+                alert('Failed to deregister');
+            }
+        });
+
+        req.error(this, function(inSender, inResponse) {
+            alert('Failed to deregister');
+        });
+
+        req.go();
+    }
+});
diff --git a/www/jssrc/blerg/EmailVerify.js b/www/jssrc/blerg/EmailVerify.js
new file mode 100644 (file)
index 0000000..c65a0ff
--- /dev/null
@@ -0,0 +1,49 @@
+enyo.kind({
+    name: 'blerg.EmailVerify',
+    statics: {
+        locationDetect: function(l) {
+            if (l.hash.match(/^#\/email-verify\//))
+                return {kind: "blerg.EmailVerify"};
+            else
+                return false;
+        }
+    },
+    components: [
+        {name: 'verificationInProgress', content: 'Verifying...'},
+        {name: 'verificationFinished', content: 'Email address registered.', showing: false},
+        {name: 'verificationFailed', content: "Failed to verify your email address. If you copy/pasted the URL, please be sure you copied the entire URL, without line breaks. If it has been more than 15 minutes since you attempted to register, the link has expired. Please try again.", showing: false},
+        {name: 'invalidURL', content: "The URL seems malformed. If you copy/pasted the URL, please be sure you copied the entire URL, without line breaks.", showing: false}
+    ],
+    create: function() {
+        this.inherited(arguments);
+
+        var m = location.hash.match(new RegExp('^#/email-verify/(.*)$'));
+        if (m) {
+            var req = new enyo.Ajax({
+                url: '/aux/email/verify',
+                method: 'POST',
+                postBody: {
+                    data: m[1]
+                }
+            });
+
+            req.response(this, function(inSender, inResponse) {
+                this.$.verificationInProgress.hide();
+                if (inResponse.status == 'success') {
+                    this.$.verificationFinished.show();
+                } else {
+                    this.$.verificationFailed.show();
+                }
+            });
+
+            req.error(this, function(inSender, inResponse) {
+                this.$.verificationFailed.show();
+            });
+
+            req.go();
+        } else {
+            this.$.verificationInProgress.hide();
+            this.$.invalidURL.show();
+        }
+    }
+});
index 8ebe123..3c6b5b6 100644 (file)
@@ -10,6 +10,8 @@ enyo.depends(
     'Main.js',
     'SignupDialog.js',
     'PasswdForm.js',
+    'EmailForm.js',
+    'EmailVerify.js',
     'Welcome.js',
     'Pager.js',
     'User.js',