Add email verification UI
color: #333;
margin-left: 1em;
}
+
+.email-address {
+ font-weight: bold;
+}
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: [
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",
+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();
+ }
+});
+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();
+ }
+ }
+});
'Main.js',
'SignupDialog.js',
'PasswdForm.js',
+ 'EmailForm.js',
+ 'EmailVerify.js',
'Welcome.js',
'Pager.js',
'User.js',