simplify getting token communication

This commit is contained in:
2014-08-28 16:10:12 +02:00
parent 40d06156fa
commit af4510cdc6
3 changed files with 13 additions and 21 deletions
+7 -15
View File
@@ -17,21 +17,13 @@
# $('body').append frame
# window.location = "#{$obtain_token_url}"
auth_win = window.open $obtain_token_url, "_blank", "location=no"
auth_win.addEventListener "loadstop", ->
# auth_win.executeScript(code: "localStorage.setItem( 'name', '' );")
watch_loop = setInterval ->
auth_win.executeScript {code: "localStorage.getItem( 'auth_token' )"}, (values)->
token = values[0]
if token
clearInterval( watch_loop )
auth_win.executeScript {code: "localStorage.setItem('auth_token', '');"}
auth_win.executeScript {code: "localStorage.getItem( 'user_id' )"}, (user_id_values)->
user_id = user_id_values[0]
Qstorage.setItem 'user_id', user_id
Qstorage.setItem 'auth_token', token
auth_win.close()
, 200
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(/auth_token=([\w-]+)/)[1]
Qstorage.setItem 'user_id', user_id
Qstorage.setItem 'auth_token', token
auth_win.close()
Ember.$.ajaxPrefilter (options) ->
if options.type.toUpperCase() == 'GET'