diff --git a/Gemfile.lock b/Gemfile.lock index fafbc365..5c588e41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index beb3183a..55874a7b 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -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) -> diff --git a/assets/javascripts/app/store/rest_adapter.coffee b/assets/javascripts/app/store/rest_adapter.coffee index efcffed0..4b1f8b87 100644 --- a/assets/javascripts/app/store/rest_adapter.coffee +++ b/assets/javascripts/app/store/rest_adapter.coffee @@ -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)) diff --git a/assets/javascripts/lib/travis/auth.coffee b/assets/javascripts/lib/travis/auth.coffee index 0abcbc0c..a9773c18 100644 --- a/assets/javascripts/lib/travis/auth.coffee +++ b/assets/javascripts/lib/travis/auth.coffee @@ -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: $('