2014-11-28 20:49:41 -05:00
|
|
|
{backboneFailure, genericFailure, parseServerError} = require 'core/errors'
|
2014-01-03 13:32:13 -05:00
|
|
|
User = require 'models/User'
|
2014-11-28 20:49:41 -05:00
|
|
|
storage = require 'core/storage'
|
2014-01-03 13:32:13 -05:00
|
|
|
BEEN_HERE_BEFORE_KEY = 'beenHereBefore'
|
|
|
|
|
2014-04-02 16:12:24 -04:00
|
|
|
init = ->
|
|
|
|
module.exports.me = window.me = new User(window.userObject) # inserted into main.html
|
2014-05-30 19:20:20 -04:00
|
|
|
module.exports.me.onLoaded()
|
2014-04-02 16:12:24 -04:00
|
|
|
trackFirstArrival()
|
|
|
|
if me and not me.get('testGroupNumber')?
|
|
|
|
# Assign testGroupNumber to returning visitors; new ones in server/routes/auth
|
|
|
|
me.set 'testGroupNumber', Math.floor(Math.random() * 256)
|
2014-06-11 14:34:52 -04:00
|
|
|
me.patch()
|
2014-04-02 16:12:24 -04:00
|
|
|
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.listenTo me, 'sync', -> Backbone.Mediator.publish('auth:me-synced', me: me)
|
2014-04-02 16:12:24 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
module.exports.logoutUser = ->
|
2016-03-09 17:39:40 -05:00
|
|
|
# TODO: Refactor to use User.logout
|
2014-01-09 13:48:51 -05:00
|
|
|
FB?.logout?()
|
2015-02-24 11:54:30 -05:00
|
|
|
callback = ->
|
2015-12-18 13:02:03 -05:00
|
|
|
location = _.result(currentView, 'logoutRedirectURL')
|
|
|
|
if location
|
|
|
|
window.location = location
|
|
|
|
else
|
|
|
|
window.location.reload()
|
2015-02-24 11:54:30 -05:00
|
|
|
res = $.post('/auth/logout', {}, callback)
|
2014-01-03 13:32:13 -05:00
|
|
|
res.fail(genericFailure)
|
|
|
|
|
2016-05-11 17:39:26 -04:00
|
|
|
module.exports.sendRecoveryEmail = (email, options={}) ->
|
|
|
|
options = _.merge(options,
|
|
|
|
{method: 'POST', url: '/auth/reset', data: { email }}
|
|
|
|
)
|
|
|
|
$.ajax(options)
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onSetVolume = (e) ->
|
|
|
|
return if e.volume is me.get('volume')
|
|
|
|
me.set('volume', e.volume)
|
|
|
|
me.save()
|
|
|
|
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.subscribe('level:set-volume', onSetVolume, module.exports)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
trackFirstArrival = ->
|
|
|
|
# will have to filter out users who log in with existing accounts separately
|
|
|
|
# but can at least not track logouts as first arrivals using local storage
|
2014-01-26 17:44:08 -05:00
|
|
|
beenHereBefore = storage.load(BEEN_HERE_BEFORE_KEY)
|
2014-01-03 13:32:13 -05:00
|
|
|
return if beenHereBefore
|
2014-01-06 20:45:35 -05:00
|
|
|
window.tracker?.trackEvent 'First Arrived'
|
2014-01-26 17:44:08 -05:00
|
|
|
storage.save(BEEN_HERE_BEFORE_KEY, true)
|
2014-04-02 16:12:24 -04:00
|
|
|
|
|
|
|
init()
|