2014-05-27 15:33:50 +02:00
|
|
|
# Homework - Server Side
|
2014-05-28 18:45:41 +02:00
|
|
|
console.log "Started Homework server!"
|
2014-05-30 08:27:49 +02:00
|
|
|
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"
|
2014-05-28 18:45:41 +02:00
|
|
|
|
2015-03-07 17:50:26 +01:00
|
|
|
notes = share.notes
|
2014-05-28 18:45:41 +02:00
|
|
|
getUser = (id) -> Meteor.users.findOne { _id: id }
|
2014-06-03 14:34:06 +02:00
|
|
|
isUsers = (u,doc) -> u and doc.userId is u
|
2014-05-27 16:02:37 +02:00
|
|
|
|
2014-05-28 10:19:06 +02:00
|
|
|
# Returns true if the user has verified at least one email address
|
|
|
|
userValidated = (user) ->
|
2014-06-01 11:47:27 +02:00
|
|
|
return no unless user?
|
2015-03-02 15:55:29 +01:00
|
|
|
return yes if user.services.twitter or user.services.facebook
|
2014-05-28 10:19:06 +02:00
|
|
|
return yes for mail in user.emails when mail.verified is yes; no
|
|
|
|
|
2014-10-09 16:46:23 +02:00
|
|
|
Meteor.publish 'user', ->
|
|
|
|
Meteor.users.find @userId, fields: {dateformat: 1, username: 1}
|
2014-05-30 08:27:49 +02:00
|
|
|
# Publish user's notes to each user.
|
2014-11-15 10:22:48 +01:00
|
|
|
Meteor.publish "notes", (archived) ->
|
2014-05-28 18:45:41 +02:00
|
|
|
if userValidated getUser(@userId)
|
2014-11-15 10:22:48 +01:00
|
|
|
notes.find userId: @userId, archived: archived
|
2014-05-27 15:33:50 +02:00
|
|
|
|
2014-09-27 08:50:28 +02:00
|
|
|
# Custom new account default settings
|
|
|
|
Accounts.onCreateUser (options, user) ->
|
|
|
|
user.dateformat = options.dateformat or "MM/DD/YYYY"
|
|
|
|
return user
|
|
|
|
|
2014-06-03 14:34:06 +02:00
|
|
|
# Database Permissions
|
|
|
|
# Allow all users to insert, update and remove their notes.
|
|
|
|
notes.allow insert: isUsers, update: isUsers, remove: isUsers
|
|
|
|
|
2014-05-28 10:19:06 +02:00
|
|
|
# Methods that the clients can invoke
|
|
|
|
Meteor.methods
|
2014-06-05 17:03:10 +02:00
|
|
|
# Request another confirmation email.
|
2014-05-28 18:45:41 +02:00
|
|
|
resendConfirmEmail: ->
|
|
|
|
u = getUser(@userId)
|
|
|
|
if not u
|
2014-05-30 10:33:32 +02:00
|
|
|
console.log "Validating nonexisting user!"; return no
|
2014-05-28 18:45:41 +02:00
|
|
|
if userValidated(u) is no
|
|
|
|
Accounts.sendVerificationEmail @userId
|
|
|
|
console.log "Sent verification email to "+u.emails[0].address
|
|
|
|
return yes
|
|
|
|
else
|
|
|
|
console.log "User "+u.emails[0].address+" already validated."
|
|
|
|
return no
|
2014-06-05 17:03:10 +02:00
|
|
|
# Request user's account to be deleted
|
2014-05-28 18:45:41 +02:00
|
|
|
deleteMe: ->
|
|
|
|
if @userId
|
|
|
|
Meteor.users.remove @userId
|
|
|
|
# Automagically log out the user by invalidating every token he has
|
|
|
|
Meteor.users.update {_id: @userId},
|
|
|
|
{$set : { "resume.loginTokens" : [] } }, { multi: yes }
|
2014-05-30 10:33:32 +02:00
|
|
|
return yes
|
2014-06-05 17:03:10 +02:00
|
|
|
no
|
2014-10-01 08:42:06 +02:00
|
|
|
|
|
|
|
# Allow users to change their date format
|
2014-09-26 12:59:23 +02:00
|
|
|
Meteor.users.allow
|
|
|
|
update: (id,doc,fields,mod) ->
|
|
|
|
if fields[0] == 'dateformat' and fields.length == 1
|
|
|
|
return yes
|
|
|
|
return no
|