mirror of
https://github.com/fazo96/homework.git
synced 2025-01-09 12:10:08 +01:00
new file organization
This commit is contained in:
parent
fdbfdb66ac
commit
2d92401442
@ -1,18 +1,19 @@
|
||||
# Homework - Client Side
|
||||
notes = new Meteor.Collection "notes"
|
||||
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
||||
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
|
||||
|
||||
# Common Helpers
|
||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||
UI.registerHelper "mail", -> getUser().emails[0].address
|
||||
UI.registerHelper "verified", -> amIValid()
|
||||
|
||||
# Client Templates
|
||||
|
||||
# User Interface
|
||||
Template.userInfo.events
|
||||
'click #logout': (e,template) -> Meteor.logout()
|
||||
|
@ -1,6 +1,9 @@
|
||||
# Homework - Server Side
|
||||
console.log "Started Homework server!"
|
||||
console.log "Sending emails using "+process.env.MAIL_URL
|
||||
if process.env.MAIL_URL
|
||||
console.log "Sending emails using "+process.env.MAIL_URL
|
||||
else
|
||||
console.log "Not Sending Emails, please set the MAIL_URL environment variable"
|
||||
|
||||
notes = new Meteor.Collection "notes"
|
||||
|
||||
@ -23,9 +26,11 @@ Accounts.emailTemplates.verifyEmail.text = (user,url) ->
|
||||
# Returns true if the user has verified at least one email address
|
||||
userValidated = (user) ->
|
||||
if not user?
|
||||
throw new Meteor.Exception "Impossible! Trying to validate null user"
|
||||
console.log "Impossible! Trying to validate null user"
|
||||
return no
|
||||
return yes for mail in user.emails when mail.verified is yes; no
|
||||
|
||||
# Publish user's notes to each user.
|
||||
Meteor.publish "my-notes", ->
|
||||
if userValidated getUser(@userId)
|
||||
notes.find userId: @userId
|
||||
@ -39,10 +44,6 @@ Accounts.validateNewUser (user) ->
|
||||
|
||||
# Methods that the clients can invoke
|
||||
Meteor.methods
|
||||
amIValidated: ->
|
||||
u = getUser(@userId)
|
||||
return no unless u?
|
||||
userValidated u
|
||||
resendConfirmEmail: ->
|
||||
u = getUser(@userId)
|
||||
if not u
|
||||
|
5
shared/utils.coffee
Normal file
5
shared/utils.coffee
Normal file
@ -0,0 +1,5 @@
|
||||
# Utility functions for client and server - Homework
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user