Basic user authentication page and provider support
This commit is contained in:
@@ -13,9 +13,26 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
unauthorized: ->
|
||||
Qstorage.setItem('auth_token', '')
|
||||
@controllerFor('application').set 'list', null
|
||||
App.obtain_token(t('messages.unauthorized'))
|
||||
@send 'obtain_token'
|
||||
@controllerFor('application').redirect_to 'index', message: 'unauthorized'
|
||||
|
||||
handleAuthInfo: (user_id, auth_token)->
|
||||
Qstorage.setItem 'user_id', user_id
|
||||
Qstorage.setItem 'auth_token', auth_token
|
||||
controller = @controllerFor('application')
|
||||
controller.setCurrentList()
|
||||
controller.set 'notice', t('messages.authenticated')
|
||||
actions:
|
||||
obtain_token: ( options = {} ) ->
|
||||
provider = options.provider || 'facebook'
|
||||
auth_win = window.open "#{$obtain_token_url}?provider=#{provider}", "_blank", "location=no"
|
||||
auth_win.addEventListener "loadstart", (event)=>
|
||||
if event.url.match 'close_window'
|
||||
user_id = event.url.match(/user_id=([\w+-]+)/)[1]
|
||||
auth_token = event.url.match(/authentication_token=([\w-]+)/)[1]
|
||||
@handleAuthInfo(user_id, auth_token)
|
||||
auth_win.close()
|
||||
true
|
||||
openModal: (modalName, model)->
|
||||
@controllerFor(modalName).set('model', model)
|
||||
@render modalName,
|
||||
@@ -102,6 +119,7 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
message = 'general_error'
|
||||
appcontroller.redirect_to 'index', message: message
|
||||
scanQr: ->
|
||||
return @transitionTo('sign_in') unless Qstorage.getItem('auth_token')
|
||||
<% if Rails.env.user_app? %>
|
||||
ar = @
|
||||
scanner = cordova.require("cordova/plugin/BarcodeScanner")
|
||||
|
||||
Reference in New Issue
Block a user