Merge branch 'sf-auth-iframe' of github.com:travis-ci/travis-ember into sf-auth-iframe
Conflicts: public/stylesheets/application.css
This commit is contained in:
commit
b3c310d51d
|
@ -22,7 +22,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-api.git
|
remote: git://github.com/travis-ci/travis-api.git
|
||||||
revision: 6606af4b43ef64d3ef97efeddda8524aff7c5281
|
revision: 1e903129a31ab7785e17562740d0bfb69486e2f3
|
||||||
branch: sf-use-services
|
branch: sf-use-services
|
||||||
specs:
|
specs:
|
||||||
travis-api (0.0.1)
|
travis-api (0.0.1)
|
||||||
|
|
|
@ -20,10 +20,6 @@ require 'travis/auth'
|
||||||
|
|
||||||
Travis.reopen
|
Travis.reopen
|
||||||
App: Em.Application.extend
|
App: Em.Application.extend
|
||||||
USER_PAYLOAD:
|
|
||||||
user: { id: 1, login: 'svenfuchs', name: 'Sven Fuchs', email: 'me@svenfuchs.com', token: '1234567890', gravatar: '402602a60e500e85f2f5dc1ff3648ecb', locale: 'en', repo_count: 2, synced_at: '2012-09-15T20:53:14Z' }
|
|
||||||
accounts: [{ login: 'travis-ci', name: 'Travis CI', type: 'org', repoCounts: 1 }]
|
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
@_super()
|
@_super()
|
||||||
@connect()
|
@connect()
|
||||||
|
@ -35,23 +31,24 @@ Travis.reopen
|
||||||
@pusher = new Travis.Pusher()
|
@pusher = new Travis.Pusher()
|
||||||
@tailing = new Travis.Tailing()
|
@tailing = new Travis.Tailing()
|
||||||
|
|
||||||
@setCurrentUser(JSON.parse($.cookie('user')))
|
#@setCurrentUser(JSON.parse($.cookie('user')))
|
||||||
|
|
||||||
signIn: ->
|
signIn: ->
|
||||||
# user = Travis.Auth.signIn()
|
Travis.Auth.signIn()
|
||||||
# console.log(user)
|
# TODO: this has to mov, no?
|
||||||
@setCurrentUser(@USER_PAYLOAD)
|
|
||||||
@render.apply(this, @get('returnTo') || ['home', 'index'])
|
@render.apply(this, @get('returnTo') || ['home', 'index'])
|
||||||
|
|
||||||
signOut: ->
|
signOut: ->
|
||||||
|
Travis.config.access_token = null
|
||||||
@setCurrentUser()
|
@setCurrentUser()
|
||||||
|
|
||||||
setCurrentUser: (data) ->
|
setCurrentUser: (data) ->
|
||||||
data = JSON.parse(data) if typeof data == 'string'
|
data = JSON.parse(data) if typeof data == 'string'
|
||||||
$.cookie('user', JSON.stringify(data))
|
#$.cookie('user', JSON.stringify(data))
|
||||||
if data
|
if data
|
||||||
@store.load(Travis.User, data.user)
|
@store.load(Travis.User, data.user)
|
||||||
@store.loadMany(Travis.Account, data.accounts)
|
# TODO: this throws an error
|
||||||
|
#@store.loadMany(Travis.Account, data.accounts)
|
||||||
@set('currentUser', if data then Travis.User.find(data.user.id) else undefined)
|
@set('currentUser', if data then Travis.User.find(data.user.id) else undefined)
|
||||||
|
|
||||||
render: (name, action, params) ->
|
render: (name, action, params) ->
|
||||||
|
|
|
@ -30,4 +30,7 @@ jQuery.support.cors = true
|
||||||
|
|
||||||
ajax: (url, method, options) ->
|
ajax: (url, method, options) ->
|
||||||
endpoint = Travis.config.api_endpoint || ''
|
endpoint = Travis.config.api_endpoint || ''
|
||||||
|
if Travis.config.access_token
|
||||||
|
options.headers ||= {}
|
||||||
|
options.headers['Authorization'] ||= "token #{Travis.config.access_token}"
|
||||||
@_super("#{endpoint}#{url}", method, $.extend(options, @DEFAULT_OPTIONS))
|
@_super("#{endpoint}#{url}", method, $.extend(options, @DEFAULT_OPTIONS))
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
@Travis.Auth = ->
|
@Travis.Auth = ->
|
||||||
$ => @iframe.appendTo('body')
|
$ =>
|
||||||
|
@iframe.appendTo('body')
|
||||||
|
window.addEventListener "message", (e) => @receiveMessage(e)
|
||||||
this
|
this
|
||||||
|
|
||||||
$.extend Travis.Auth,
|
$.extend Travis.Auth,
|
||||||
|
@ -11,7 +13,23 @@ $.extend Travis.Auth,
|
||||||
$.extend Travis.Auth.prototype,
|
$.extend Travis.Auth.prototype,
|
||||||
iframe: $('<iframe id="auth-frame" />').hide()
|
iframe: $('<iframe id="auth-frame" />').hide()
|
||||||
|
|
||||||
signIn: ->
|
expectedOrigin: ->
|
||||||
|
if Travis.config.api_endpoint[0] == '/'
|
||||||
|
window.location.protocol + "://" + window.location.host
|
||||||
|
else
|
||||||
|
Travis.config.api_endpoint
|
||||||
|
|
||||||
|
receiveMessage: (event) ->
|
||||||
|
if event.origin != @expectedOrigin()
|
||||||
|
console.log("unexpected message #{event.origin}: #{event.data}")
|
||||||
|
else
|
||||||
|
Travis.config.access_token = event.data.token
|
||||||
|
Travis.app.setCurrentUser(event.data.user)
|
||||||
|
console.log('sign in!')
|
||||||
|
|
||||||
|
trySignIn: ->
|
||||||
@iframe.attr('src', "#{Travis.config.api_endpoint}/auth/post_message")
|
@iframe.attr('src', "#{Travis.config.api_endpoint}/auth/post_message")
|
||||||
@iframe.show()
|
|
||||||
console.log('sign in!')
|
signIn: ->
|
||||||
|
@trySignIn()
|
||||||
|
# TODO: timeout for redirect goes here
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user