2012-12-10 02:39:29 +08:00
|
|
|
define [
|
2014-04-25 05:33:59 +08:00
|
|
|
'jquery',
|
2012-12-10 02:39:29 +08:00
|
|
|
'underscore',
|
2014-04-25 05:33:59 +08:00
|
|
|
'backbone',
|
|
|
|
'globals',
|
|
|
|
], ($, _, Backbone, globals) ->
|
2012-12-10 02:39:29 +08:00
|
|
|
|
|
|
|
AuthenticationModel = Backbone.Model.extend
|
2014-04-25 05:33:59 +08:00
|
|
|
#url: '/auth'
|
2012-12-10 02:39:29 +08:00
|
|
|
defaults:
|
2012-12-11 09:51:01 +08:00
|
|
|
username: null
|
2014-04-25 05:33:59 +08:00
|
|
|
meetingId: null
|
2014-04-25 22:34:26 +08:00
|
|
|
externalMeetingId: null
|
2014-04-25 05:33:59 +08:00
|
|
|
userId: null
|
2012-12-10 02:39:29 +08:00
|
|
|
loginAccepted: false
|
|
|
|
|
2014-04-25 05:33:59 +08:00
|
|
|
authenticate: (callbacks) ->
|
|
|
|
message =
|
2014-04-25 22:34:26 +08:00
|
|
|
header:
|
|
|
|
timestamp: new Date().getTime()
|
|
|
|
name: "validate_auth_token_request"
|
|
|
|
payload:
|
|
|
|
auth_token: getURLParameter("auth_token")
|
2014-04-25 05:33:59 +08:00
|
|
|
|
|
|
|
console.log "Sending authentication message", message
|
2014-04-25 22:34:26 +08:00
|
|
|
globals.events.on "message", (received) =>
|
|
|
|
console.log "Authentication response", received
|
2014-04-25 05:33:59 +08:00
|
|
|
if received?.header?.name is "validate_auth_token_reply"
|
2014-04-25 22:34:26 +08:00
|
|
|
@set("username", received.payload.fullname)
|
|
|
|
@set("meetingId", received.payload.meeting_id)
|
|
|
|
@set("externalMeetingId", received.payload.external_meeting_id)
|
|
|
|
@set("userId", received.payload.user_id)
|
2014-04-25 05:33:59 +08:00
|
|
|
callbacks(null, received)
|
|
|
|
globals.connection.emit(message)
|
|
|
|
|
2014-04-25 22:34:26 +08:00
|
|
|
getURLParameter = (name) ->
|
|
|
|
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")
|
|
|
|
regexS = "[\\?&]"+name+"=([^&#]*)"
|
|
|
|
regex = new RegExp(regexS)
|
|
|
|
results = regex.exec(location.search)
|
|
|
|
unless results?
|
|
|
|
""
|
|
|
|
else
|
|
|
|
decodeURIComponent(results[1].replace(/\+/g, " "))
|
|
|
|
|
2012-12-10 02:39:29 +08:00
|
|
|
AuthenticationModel
|