Make Account Center only usable when logged in
[blerg.git] / www / jssrc / blerg / EmailVerify.js
1 enyo.kind({
2     name: 'blerg.EmailVerify',
3     statics: {
4         locationDetect: function(l) {
5             if (l.hash.match(/^#\/email-verify\//))
6                 return {kind: "blerg.EmailVerify"};
7             else
8                 return false;
9         }
10     },
11     components: [
12         {name: 'verificationInProgress', content: 'Verifying...'},
13         {name: 'verificationFinished', content: 'Email address registered.', showing: false},
14         {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},
15         {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}
16     ],
17     create: function() {
18         this.inherited(arguments);
19
20         var m = location.hash.match(new RegExp('^#/email-verify/(.*)$'));
21         if (m) {
22             var req = new enyo.Ajax({
23                 url: '/aux/email/verify',
24                 method: 'POST',
25                 postBody: {
26                     data: m[1]
27                 }
28             });
29
30             req.response(this, function(inSender, inResponse) {
31                 this.$.verificationInProgress.hide();
32                 if (inResponse.status == 'success') {
33                     this.$.verificationFinished.show();
34                 } else {
35                     this.$.verificationFailed.show();
36                 }
37             });
38
39             req.error(this, function(inSender, inResponse) {
40                 this.$.verificationFailed.show();
41             });
42
43             req.go();
44         } else {
45             this.$.verificationInProgress.hide();
46             this.$.invalidURL.show();
47         }
48     }
49 });