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:
Sven Fuchs 2012-09-18 20:31:24 +02:00
commit b3c310d51d
6 changed files with 885 additions and 3701 deletions

View File

@ -22,7 +22,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-api.git
revision: 6606af4b43ef64d3ef97efeddda8524aff7c5281
revision: 1e903129a31ab7785e17562740d0bfb69486e2f3
branch: sf-use-services
specs:
travis-api (0.0.1)

View File

@ -20,10 +20,6 @@ require 'travis/auth'
Travis.reopen
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: ->
@_super()
@connect()
@ -35,23 +31,24 @@ Travis.reopen
@pusher = new Travis.Pusher()
@tailing = new Travis.Tailing()
@setCurrentUser(JSON.parse($.cookie('user')))
#@setCurrentUser(JSON.parse($.cookie('user')))
signIn: ->
# user = Travis.Auth.signIn()
# console.log(user)
@setCurrentUser(@USER_PAYLOAD)
Travis.Auth.signIn()
# TODO: this has to mov, no?
@render.apply(this, @get('returnTo') || ['home', 'index'])
signOut: ->
Travis.config.access_token = null
@setCurrentUser()
setCurrentUser: (data) ->
data = JSON.parse(data) if typeof data == 'string'
$.cookie('user', JSON.stringify(data))
#$.cookie('user', JSON.stringify(data))
if data
@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)
render: (name, action, params) ->

View File

@ -30,4 +30,7 @@ jQuery.support.cors = true
ajax: (url, method, options) ->
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))

View File

@ -1,5 +1,7 @@
@Travis.Auth = ->
$ => @iframe.appendTo('body')
$ =>
@iframe.appendTo('body')
window.addEventListener "message", (e) => @receiveMessage(e)
this
$.extend Travis.Auth,
@ -11,7 +13,23 @@ $.extend Travis.Auth,
$.extend Travis.Auth.prototype,
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.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