Files
mozo-backend/app/assets/javascripts/user/app/app.js.coffee
T

48 lines
1.7 KiB
CoffeeScript

#FB.init appId: '168928633304849'
#Ember.Application.initializer
#name: 'authentication',
#initialize: (container, application)->
## register the Facebook authenticator so the session can find it
#container.register 'authenticators:facebook', App.FacebookAuthenticator
#Ember.SimpleAuth.setup(container, application)
@App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#ember-app-container'
obtain_token: (message)->
message ||= ''
# frame = $('<iframe></iframe>').addClass('obtain-token-frame').attr 'src', $obtain_token_url
# frame.css width: $('body').outerWidth(), height: $('body').outerHeight()
# $('body').append frame
window.location = "#{$obtain_token_url}"
Ember.$.ajaxPrefilter (options) ->
if options.type.toUpperCase() == 'GET'
if auth_token = Qstorage.getItem('auth_token')
if options.data
options.data += "&auth_token=#{auth_token}"
else
options.data = "auth_token=#{auth_token}"
if options.type.toUpperCase() == 'POST'
if auth_token = Qstorage.getItem('auth_token')
if options.data
if typeof(options.data) == 'string'
if options.data[0] == '{' || options.data[0] == '[' # json
object = JSON.parse(options.data)
object.auth_token = auth_token
options.data = JSON.stringify(object)
else
options.data += "&auth_token=#{auth_token}"
else
options.data.auth_token = auth_token
else
options.data = "auth_token=#{auth_token}"
true
Ember.$.ajaxSetup
error: (jqXHR, textStatus, errorThrown)->
console.log "Error: #{textStatus}: #{errorThrown}"
if jqXHR.status == 401
App.__container__.lookup('route:application').unauthorized()