1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-26 14:44:20 +01:00
homework/server/server.coffee

34 lines
978 B
CoffeeScript
Raw Normal View History

# Homework - Server Side
notes = new Meteor.Collection "notes"
2014-05-27 16:02:37 +02:00
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
Accounts.config {
2014-05-27 15:34:25 +02:00
sendVerificationEmail: false
loginExpirationInDays: 1
}
2014-05-28 10:19:06 +02:00
# Returns true if the user has verified at least one email address
userValidated = (user) ->
return yes for mail in user.emails when mail.verified is yes; no
Meteor.publish "my-notes", ->
2014-05-28 10:19:06 +02:00
# TODO: Don't publish unless user is validated
notes.find( { userId: @userId } ) unless not @userId
# Authentication
Accounts.validateNewUser (user) ->
2014-05-27 16:02:37 +02:00
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
2014-05-28 10:19:06 +02:00
# Methods that the clients can invoke
Meteor.methods
amIValidated: ->
user = Meteor.users.findOne { _id: @userId }
return no unless user?
userValidated user