refactor auth/user/accounts

This commit is contained in:
Sven Fuchs 2012-09-27 17:13:45 +02:00
parent 8c9f9bc4f8
commit d3e1fa2274
11 changed files with 39 additions and 40 deletions

View File

@ -34,15 +34,15 @@ GIT
GIT
remote: git://github.com/roidrage/hubble
revision: 8972b940a4f927927d2a4bdb250b3c98c04692a6
revision: f5e6301ac24eabeebaf8f4485d71cdcf93b2f3f8
specs:
hubble (0.1.2)
faraday
json (~> 1.6.5)
json (~> 1.6)
GIT
remote: git://github.com/travis-ci/travis-api.git
revision: 228f71f407787f669d6d5ee731a2d5409918dc8e
revision: f2e8ccafc1efb0da8e14c2e03021d27dd1b40431
specs:
travis-api (0.0.1)
backports (~> 2.5)
@ -60,7 +60,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: a4b1446e3746a5ff59a5438a34f7b2471e33a731
revision: 6d8de39fa098965aad52b51f8f9a3f5490e7def5
branch: sf-more-services
specs:
travis-core (0.0.1)
@ -155,10 +155,10 @@ GEM
multi_json (~> 1.0)
faraday (0.8.4)
multipart-post (~> 1.1)
foreman (0.59.0)
foreman (0.60.0)
thor (>= 0.13.6)
fssm (0.2.9)
guard (1.3.3)
guard (1.4.0)
listen (>= 0.4.2)
thor (>= 0.14.6)
hashr (0.0.22)
@ -166,7 +166,7 @@ GEM
hitimes (1.1.1)
i18n (0.6.1)
journey (1.0.4)
json (1.6.7)
json (1.7.5)
kgio (2.7.4)
listen (0.5.2)
mail (2.4.4)
@ -202,7 +202,7 @@ GEM
rack
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack-test (0.6.2)
rack (>= 1.0)
railties (3.2.8)
actionpack (= 3.2.8)

View File

@ -23,7 +23,6 @@ Travis.reopen
App: Em.Application.extend
autoinit: false
currentUserBinding: 'auth.user'
accessTokenBinding: 'auth.user.accessToken'
authStateBinding: 'auth.state'
init: ->

View File

@ -9,6 +9,10 @@
window.addEventListener('message', (e) => @receiveMessage(e))
Ember.run.next(this, @loadUser)
accessToken: (->
sessionStorage.getItem('travis.token')
).property()
# if the user is in the session storage, we're using it. if we have a flag
# for auto signin then we're trying to sign in.
loadUser: ->
@ -45,11 +49,11 @@
@set('user', if user then user else undefined)
storeUser: (data) ->
data.user.access_token ||= data.token # TODO why's the access_token not set on the user?
localStorage?.setItem('travis.auto_signin', 'true')
sessionStorage?.setItem('travis.user', JSON.stringify(data))
sessionStorage?.setItem('travis.token', data.token)
@notifyPropertyChange('accessToken')
@store.load(Travis.User, data.user)
@store.loadMany(Travis.Account, data.accounts)
Travis.User.find(data.user.id)
receiveMessage: (event) ->

View File

@ -10,7 +10,7 @@ Travis.AccountsController = Ember.ArrayController.extend
this["view#{$.camelize(tab)}"](params)
viewAccounts: ->
@set('content', Travis.Account.filter())
@set('content', Travis.Account.find())
findByLogin: (login) ->
@find (account) -> account.get('login') == 'login'

View File

@ -11,7 +11,6 @@ require 'travis/model'
isSyncing: DS.attr('boolean')
syncedAt: DS.attr('string')
repoCount: DS.attr('number')
accessToken: DS.attr('string')
init: ->
@poll() if @get('isSyncing')
@ -30,12 +29,12 @@ require 'travis/model'
).property()
sync: ->
@post('/profile/sync')
@post('/user/sync')
@set('isSyncing', true)
@poll()
poll: ->
@ajax '/profile', 'get', success: (data) =>
@ajax '/user', 'get', success: (data) =>
if data.user.is_syncing
Ember.run.later(this, this.poll.bind(this), 3000)
else
@ -47,10 +46,6 @@ require 'travis/model'
setWithSession: (name, value) ->
@set(name, value)
data = JSON.parse(sessionStorage?.getItem('travis.user'))
data.user[$.underscore(name)] = @get(name)
sessionStorage?.setItem('travis.user', JSON.stringify(data))
@Travis.User.reopenClass
url: 'profile'
user = JSON.parse(sessionStorage?.getItem('travis.user'))
user[$.underscore(name)] = @get(name)
sessionStorage?.setItem('travis.user', JSON.stringify(user))

View File

@ -9,12 +9,13 @@ jQuery.support.cors = true
@ajax(url, 'post', data: data, success: callback)
ajax: (url, method, options) ->
console.log(url)
endpoint = Travis.config.api_endpoint || ''
options = options || {}
if access_token = Travis.app?.get('accessToken')
if accessToken = Travis.app?.get('auth.accessToken')
options.headers ||= {}
options.headers['Authorization'] ||= "token #{access_token}"
options.headers['Authorization'] ||= "token #{accessToken}"
options.url = "#{endpoint}#{url}"
options.type = method

View File

@ -3132,8 +3132,8 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (cachedValue) {
var key = association.options.key || get(this, 'namingConvention').keyToJSONKey(name),
ids = data.get(key) || [];
var clientIds;
var clientIds;
if(association.options.embedded) {
clientIds = store.loadMany(association.type, ids).clientIds;
} else {
@ -3141,7 +3141,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
return store.clientIdForId(association.type, id);
});
}
set(cachedValue, 'content', Ember.A(clientIds));
cachedValue.fetch();
}
@ -3766,7 +3766,7 @@ DS.FixtureAdapter = DS.Adapter.extend({
return ids.indexOf(item.id) !== -1;
});
}
if (fixtures) {
this.simulateRemoteCall(function() {
store.loadMany(type, fixtures);
@ -3786,7 +3786,7 @@ DS.FixtureAdapter = DS.Adapter.extend({
findQuery: function(store, type, query, array) {
var fixtures = this.fixturesForType(type);
Ember.assert("Unable to find fixtures for model type "+type.toString(), !!fixtures);
fixtures = this.queryFixtures(fixtures, query);
@ -3847,7 +3847,7 @@ var get = Ember.get, set = Ember.set;
DS.RESTAdapter = DS.Adapter.extend({
bulkCommit: false,
createRecord: function(store, type, record) {
var root = this.rootForType(type);

View File

@ -90,7 +90,7 @@
&.user
background-image: inline-image('ui/user.png')
background-position: 29px 18px
&.org
&.organization
background-image: inline-image('ui/org.png')
background-position: 24px 18px
.summary

File diff suppressed because one or more lines are too long

View File

@ -27455,8 +27455,8 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (cachedValue) {
var key = association.options.key || get(this, 'namingConvention').keyToJSONKey(name),
ids = data.get(key) || [];
var clientIds;
var clientIds;
if(association.options.embedded) {
clientIds = store.loadMany(association.type, ids).clientIds;
} else {
@ -27464,7 +27464,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
return store.clientIdForId(association.type, id);
});
}
set(cachedValue, 'content', Ember.A(clientIds));
cachedValue.fetch();
}
@ -28089,7 +28089,7 @@ DS.FixtureAdapter = DS.Adapter.extend({
return ids.indexOf(item.id) !== -1;
});
}
if (fixtures) {
this.simulateRemoteCall(function() {
store.loadMany(type, fixtures);
@ -28109,7 +28109,7 @@ DS.FixtureAdapter = DS.Adapter.extend({
findQuery: function(store, type, query, array) {
var fixtures = this.fixturesForType(type);
Ember.assert("Unable to find fixtures for model type "+type.toString(), !!fixtures);
fixtures = this.queryFixtures(fixtures, query);
@ -28170,7 +28170,7 @@ var get = Ember.get, set = Ember.set;
DS.RESTAdapter = DS.Adapter.extend({
bulkCommit: false,
createRecord: function(store, type, record) {
var root = this.rootForType(type);

View File

@ -2005,7 +2005,7 @@ body > div {
}
/* line 13, /Users/sven/Development/projects/travis/travis-ember/assets/stylesheets/layout.sass */
body > div, body > div > div, body > div > div > div {
body > div, body > div > div {
width: 100%;
min-height: 100%;
display: -webkit-box;
@ -2639,7 +2639,7 @@ body > div, body > div > div, body > div > div > div {
background-position: 29px 18px;
}
/* line 93, /Users/sven/Development/projects/travis/travis-ember/assets/stylesheets/left/list.sass */
#accounts li.org {
#accounts li.organization {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAMCAMAAAC3DnawAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5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