From 475181698ed67a27978911d70aa0b1eb269edc9e Mon Sep 17 00:00:00 2001 From: fazo96 Date: Thu, 5 Jun 2014 17:03:10 +0200 Subject: [PATCH] code clean up --- client/client.coffee | 30 ++++++++-------------- client/view/style.css | 1 + client/view/templates.html | 52 +++++++++++++++++++++++++------------- server/accounts.coffee | 15 ++++++----- server/server.coffee | 5 +++- 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/client/client.coffee b/client/client.coffee index fe40074..8c8c7d7 100644 --- a/client/client.coffee +++ b/client/client.coffee @@ -1,6 +1,6 @@ # Homework - Client Side - -# Variables and utility stuff +homework_version = "1.0" +# Utilities notes = new Meteor.Collection "notes" getUser = -> Meteor.user() deleteAccount = -> @@ -33,6 +33,7 @@ Router.configure Router.map -> @route 'home', path: '/' + template: 'homepage' action: -> @render 'homepage', to: 'outside' onBeforeAction: -> # Dispatch user to the right landing page based on his account status @@ -53,13 +54,6 @@ Router.map -> path: '/archive/:_id?' waitOn: -> Meteor.subscribe "archive" onBeforeAction: -> if not getUser() then Router.go 'home' - ### - @route 'note', - path: '/note/:_id' - waitOn: -> Meteor.subscribe "my-notes" - data: -> notes.findOne _id: @params._id - onBeforeAction: -> if not @data()? then Router.go 'home' - ### @route 'verifyEmail', path: '/verify/:token?' template: 'verifyEmail' @@ -82,7 +76,7 @@ Deps.autorun -> # Client Templates -# Some utilities +# Some utility callbacks logoutCallback = (err) -> if err then errCallback err else Router.go 'home'; Meteor.unsubscribe "my-notes" @@ -91,18 +85,18 @@ errCallback = (err) -> showError msg: err.reason else showErrror msg: err -# Menu +# 3 Buttons navigation Menu Template.menu.events 'click .go-home': -> Router.go 'home' 'click .go-account': -> Router.go 'account' 'click .go-archive': -> Router.go 'archive' -# User Interface +# Account Page Template.account.events 'click #btn-logout': (e,template) -> Meteor.logout logoutCallback 'click #btn-delete-me': -> deleteAccount() -# Notes template +# Notes list Template.notelist.active = -> return no unless Router.current() and Router.current().data() return @_id is Router.current().data()._id @@ -157,13 +151,11 @@ saveCurrentNote = (t,e) -> content: t.find('.area').value date: t.find('.date').value Template.editor.events - 'click .close-editor': -> - Router.go 'notes' - #if Router.current().path.startsWith '/note' then Router.go 'notes' + 'click .close-editor': -> Router.go 'notes' 'click .save-editor': (e,t) -> saveCurrentNote t 'keypress .title': (e,t) -> saveCurrentNote t, e -# Notifications +# Notifications (not used yet) alerts = [] alertDep = new Deps.Dependency # Show a notification @@ -191,7 +183,7 @@ clearError = -> shownError = undefined; errorDep.changed() Template.error.error = -> errorDep.depend(); shownError Template.error.events 'click .close': -> clearError() -# Verify Email +# Verify Email page Template.verifyEmail.events 'click #btn-verify': (e,template) -> t = template.find('#token-field').value; t = t.split("/") @@ -218,7 +210,7 @@ Template.login.events 'keypress .login': (e,template) -> loginRequest e,template 'click #login-btn': (e,template) -> loginRequest null,template -# Register +# New Account page registerRequest = (e,template) -> if e and e.keyCode isnt 13 then return mail = template.find('#r-mail').value; pass = template.find('#r-pass').value diff --git a/client/view/style.css b/client/view/style.css index f5ce442..36be0c7 100644 --- a/client/view/style.css +++ b/client/view/style.css @@ -1,3 +1,4 @@ +/* Homework CSS File. I'm sorry it's a mess... */ /* Generics and bootstrap classes */ input { text-align:center; diff --git a/client/view/templates.html b/client/view/templates.html index 4248fc8..a17b86a 100644 --- a/client/view/templates.html +++ b/client/view/templates.html @@ -1,22 +1,6 @@ - - + + + + + + + + + + + + + + + + + + + + diff --git a/server/accounts.coffee b/server/accounts.coffee index e6f3795..43b78a8 100644 --- a/server/accounts.coffee +++ b/server/accounts.coffee @@ -1,20 +1,23 @@ # Homework - Server side accounts code +# Regular Expression to see if an email can be valid validateEmail = (email) -> x = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ x.test email -Accounts.validateNewUser (user) -> - mail = user.emails[0].address - if Match.test(mail,String) is no or validateEmail(mail) is no - throw new Meteor.Error 403, "Invalid Email" - return yes - Accounts.config { sendVerificationEmail: true loginExpirationInDays: 1 } +# Code that checks if a new user request is valid +Accounts.validateNewUser (user) -> + mail = user.emails[0].address + if Match.test(mail,String) is no or validateEmail(mail) is no + throw new Meteor.Error 403, "Invalid Email" + return yes + +# Email configuration code Accounts.emailTemplates.siteName = "Homework App" Accounts.emailTemplates.verifyEmail.text = (user,url) -> urlist = url.split('/'); token = urlist[urlist.length-1] diff --git a/server/server.coffee b/server/server.coffee index 7661c4c..e9c5bab 100644 --- a/server/server.coffee +++ b/server/server.coffee @@ -29,6 +29,7 @@ notes.allow insert: isUsers, update: isUsers, remove: isUsers # Methods that the clients can invoke Meteor.methods + # Request another confirmation email. resendConfirmEmail: -> u = getUser(@userId) if not u @@ -40,6 +41,7 @@ Meteor.methods else console.log "User "+u.emails[0].address+" already validated." return no + # Request user's account to be deleted deleteMe: -> if @userId Meteor.users.remove @userId @@ -47,4 +49,5 @@ Meteor.methods Meteor.users.update {_id: @userId}, {$set : { "resume.loginTokens" : [] } }, { multi: yes } return yes - else no + no + version: -> "1.0" # Request server version number.