From ccb9ca92bc95aa8c4f9c5d03bda71fe23c10e413 Mon Sep 17 00:00:00 2001 From: fazo96 Date: Wed, 28 May 2014 18:45:41 +0200 Subject: [PATCH] must confirm emails to use app now. --- .gitignore | 1 + client/client.coffee | 33 ++++++++++++++++++++++++++------- client/index.html | 31 ++++++++++++++++++++++++------- client/style.css | 7 ++++++- server/server.coffee | 41 +++++++++++++++++++++++++++++++++++------ 5 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..245773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +run.sh diff --git a/client/client.coffee b/client/client.coffee index 694b351..386ad05 100644 --- a/client/client.coffee +++ b/client/client.coffee @@ -1,16 +1,22 @@ # Homework - Client Side notes = new Meteor.Collection "notes" Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId() -user = -> Meteor.user() -# Loading (Spinning Cog) +validateEmail = (email) -> + expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ + expr.test email +getUser = -> Meteor.user() +amIValid = -> + return no unless getUser() + return yes for mail in getUser().emails when mail.verified is yes; no +# Helpers UI.registerHelper "loggingIn", -> Meteor.loggingIn() +UI.registerHelper "mail", -> getUser().emails[0].address +UI.registerHelper "verified", -> amIValid() # User Interface Template.userInfo.events 'click #logout': (e,template) -> Meteor.logout() -Template.userInfo.in = -> Meteor.user().emails[0].address - # Notes template Template.notes.truncateNoteDesc = (s) -> s #if s.length > 52 then s.slice(0,48)+"..." else s @@ -46,7 +52,10 @@ Template.editor.events # Notifications alerts = [] alertDep = new Deps.Dependency -errCallback = (err) -> showError msg: err.reason +errCallback = (err) -> + if err.reason + showError msg: err.reason + else showErrror msg: err # Show a notification notify = (data) -> alerts.push @@ -75,10 +84,20 @@ Template.error.events 'click .close': -> clearError() # "Loading" template Template.loading.status = -> Meteor.status() +# Verify Email +Template.verifyEmail.events + 'click #btn-verify': (e,template) -> + Accounts.verifyEmail template.find('#token-field').value, errCallback + 'click #btn-resend': -> + Meteor.call 'resendConfirmEmail', errCallback + 'click #btn-delete': -> Meteor.call 'deleteMe' + 'click #btn-logout': -> Meteor.logout() + # Login and Register pressLogin = (template) -> mail = template.find('#mail').value; pass = template.find('#pass').value - Meteor.loginWithPassword mail, pass, (err) -> errCallback err + Meteor.loginWithPassword mail, pass, errCallback + Template.auth.events # Login 'keypress .login': (e,template) -> if e.keyCode is 13 then pressLogin template @@ -97,6 +116,6 @@ Template.auth.events Accounts.createUser { email: mail, password: pass - }, (e) -> errCallback e + }, errCallback catch err showError msg: err diff --git a/client/index.html b/client/index.html index 453a0b3..152f1cb 100644 --- a/client/index.html +++ b/client/index.html @@ -11,8 +11,13 @@
+ {{> error}} {{#if currentUser}} - {{> editor}} {{> notes}} {{> userInfo}} + {{#if verified}} + {{> editor}} {{> notes}} {{> userInfo}} + {{else}} + {{> verifyEmail}} + {{/if}} {{else}} {{> auth}} {{/if}} @@ -43,7 +48,6 @@ @@ -62,11 +66,24 @@ + +