2014-07-26 00:36:31 +08:00
|
|
|
# Todo
|
|
|
|
# When a user is to be kicked remove their authorization token from servers
|
|
|
|
|
2014-07-28 23:00:07 +08:00
|
|
|
@Router.configure layoutTemplate: 'layout'
|
2014-06-19 04:11:29 +08:00
|
|
|
|
2014-07-28 23:00:07 +08:00
|
|
|
@Router.map ->
|
2014-06-19 04:11:29 +08:00
|
|
|
@route "login",
|
|
|
|
path: "/meeting_id=*"
|
|
|
|
action: () ->
|
2014-07-25 04:06:07 +08:00
|
|
|
self = @
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.subscribe 'users', getInSession('meetingId'), ->
|
2014-08-14 02:30:55 +08:00
|
|
|
Meteor.subscribe 'chat', getInSession('meetingId'), getInSession("userId"), ->
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.subscribe 'shapes', getInSession('meetingId'), ->
|
|
|
|
Meteor.subscribe 'slides', getInSession('meetingId'), ->
|
|
|
|
Meteor.subscribe 'meetings', getInSession('meetingId'), ->
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.subscribe 'presentations', getInSession('meetingId'), ->
|
|
|
|
self.redirect('/')
|
2014-07-10 00:06:25 +08:00
|
|
|
|
2014-06-19 05:20:32 +08:00
|
|
|
onBeforeAction: ()->
|
2014-06-19 04:11:29 +08:00
|
|
|
url = location.href
|
|
|
|
console.log "\n\nurl=#{url}\n\n"
|
2014-06-19 05:20:32 +08:00
|
|
|
#extract the meeting_id, user_id, auth_token, etc from the uri
|
2014-06-19 04:11:29 +08:00
|
|
|
if url.indexOf("meeting_id") > -1 # if the URL is /meeting_id=...&...
|
|
|
|
urlParts = url.split("&");
|
|
|
|
|
|
|
|
meetingId = urlParts[0]?.split("=")[1];
|
|
|
|
console.log "meetingId=" + meetingId
|
|
|
|
|
|
|
|
userId = urlParts[1]?.split("=")[1];
|
|
|
|
console.log "userId=" + userId
|
|
|
|
|
|
|
|
authToken = urlParts[2]?.split("=")[1];
|
|
|
|
console.log "authToken=" + authToken
|
|
|
|
|
2014-07-04 04:50:24 +08:00
|
|
|
if meetingId? and userId? and authToken?
|
2014-08-08 21:09:39 +08:00
|
|
|
# Here we need to check whether there is already a user using userId inside meetingId, if there is don't let this user log in, it is a duplicate
|
|
|
|
###
|
|
|
|
if Meteor.call("validateUserId", meetingId, userId)
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
kick user out
|
|
|
|
###
|
|
|
|
|
|
|
|
Meteor.call("validateAuthToken", meetingId, userId, authToken)
|
2014-06-27 04:11:18 +08:00
|
|
|
Meteor.call('sendMeetingInfoToClient', meetingId, userId)
|
2014-06-19 04:11:29 +08:00
|
|
|
else
|
2014-07-04 04:50:24 +08:00
|
|
|
console.log "unable to extract from the URL some of {meetingId, userId, authToken}"
|
2014-06-19 01:31:42 +08:00
|
|
|
else
|
2014-06-19 04:11:29 +08:00
|
|
|
console.log "unable to extract the required information for the meeting from the URL"
|
|
|
|
@route "main",
|
|
|
|
path: "/"
|
2014-07-18 03:45:26 +08:00
|
|
|
onBeforeAction: ->
|
2014-07-25 04:06:07 +08:00
|
|
|
self = @
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.subscribe 'users', getInSession('meetingId'), -> # callback for after users have been loaded on client
|
2014-07-25 04:06:07 +08:00
|
|
|
if not validateCredentials() # Don't let user in if they are not valid
|
|
|
|
self.redirect("logout")
|
|
|
|
else
|
2014-08-14 02:30:55 +08:00
|
|
|
Meteor.subscribe 'chat', getInSession('meetingId'), getInSession("userId"), ->
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.subscribe 'shapes', getInSession('meetingId'), ->
|
|
|
|
Meteor.subscribe 'slides', getInSession('meetingId'), ->
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.subscribe 'meetings', getInSession('meetingId'), ->
|
|
|
|
Meteor.subscribe 'presentations', getInSession('meetingId')
|
2014-06-27 23:37:33 +08:00
|
|
|
|
2014-06-24 03:11:57 +08:00
|
|
|
@route "logout",
|
|
|
|
path: "logout"
|
2014-07-18 21:41:35 +08:00
|
|
|
|
2014-07-25 04:06:07 +08:00
|
|
|
@validateCredentials = ->
|
|
|
|
u = Meteor.Users.findOne({"userId":getInSession("userId")})
|
|
|
|
# return whether they are a valid user and still have credentials in the database
|
|
|
|
u? and u.meetingId? and u.user?.extern_userid and u.user?.userid #and (1 is 2) # makes validation fail
|