Allow to sign in and sign out
This commit is contained in:
parent
50a69cccad
commit
a3622e14c9
|
@ -49,19 +49,23 @@
|
||||||
setData: (data) ->
|
setData: (data) ->
|
||||||
@storeData(data, Travis.sessionStorage)
|
@storeData(data, Travis.sessionStorage)
|
||||||
@storeData(data, Travis.storage) unless @userDataFrom(Travis.storage)
|
@storeData(data, Travis.storage) unless @userDataFrom(Travis.storage)
|
||||||
@set('user', @loadUser(data.user))
|
user = @loadUser(data.user)
|
||||||
|
# TODO: we should not use __container__ directly, how to do it better?
|
||||||
|
Travis.__container__.lookup('controller:currentUser').set('content', user)
|
||||||
|
|
||||||
@set('state', 'signed-in')
|
@set('state', 'signed-in')
|
||||||
Travis.setLocale(data.user.locale || Travis.default_locale)
|
Travis.setLocale(data.user.locale || Travis.default_locale)
|
||||||
Travis.trigger('user:signed_in', data.user)
|
Travis.trigger('user:signed_in', data.user)
|
||||||
@get('app.router').send('afterSignIn', @readAfterSignInPath())
|
#@get('app.router').send('afterSignIn', @readAfterSignInPath())
|
||||||
|
|
||||||
storeData: (data, storage) ->
|
storeData: (data, storage) ->
|
||||||
storage.setItem('travis.token', data.token)
|
storage.setItem('travis.token', data.token)
|
||||||
storage.setItem('travis.user', JSON.stringify(data.user))
|
storage.setItem('travis.user', JSON.stringify(data.user))
|
||||||
|
|
||||||
loadUser: (user) ->
|
loadUser: (user) ->
|
||||||
@app.store.load(Travis.User, user)
|
store = @app.store
|
||||||
user = @app.store.find(Travis.User, user.id)
|
store.load(Travis.User, user.id, user)
|
||||||
|
user = store.find(Travis.User, user.id)
|
||||||
user.get('permissions')
|
user.get('permissions')
|
||||||
user
|
user
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ require 'travis/ticker'
|
||||||
|
|
||||||
Travis.Controller = Em.Controller.extend()
|
Travis.Controller = Em.Controller.extend()
|
||||||
Travis.TopController = Em.Controller.extend
|
Travis.TopController = Em.Controller.extend
|
||||||
userBinding: 'Travis.app.currentUser'
|
needs: ['currentUser']
|
||||||
|
userBinding: 'controllers.currentUser'
|
||||||
|
|
||||||
Travis.ApplicationController = Em.Controller.extend
|
Travis.ApplicationController = Em.Controller.extend
|
||||||
templateName: 'layouts/home'
|
templateName: 'layouts/home'
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'travis/ajax'
|
||||||
require 'travis/model'
|
require 'travis/model'
|
||||||
|
|
||||||
@Travis.User = Travis.Model.extend
|
@Travis.User = Travis.Model.extend
|
||||||
_name: DS.attr('string', key: 'name')
|
_name: DS.attr('string')
|
||||||
email: DS.attr('string')
|
email: DS.attr('string')
|
||||||
login: DS.attr('string')
|
login: DS.attr('string')
|
||||||
token: DS.attr('string')
|
token: DS.attr('string')
|
||||||
|
@ -22,9 +22,10 @@ require 'travis/model'
|
||||||
).property('login', '_name')
|
).property('login', '_name')
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
@poll() if @get('isSyncing')
|
|
||||||
@_super()
|
@_super()
|
||||||
|
|
||||||
|
#@poll() if @get('isSyncing')
|
||||||
|
|
||||||
Ember.run.next this, ->
|
Ember.run.next this, ->
|
||||||
transaction = @get('store').transaction()
|
transaction = @get('store').transaction()
|
||||||
transaction.add this
|
transaction.add this
|
||||||
|
|
|
@ -62,3 +62,7 @@ Travis.RestAdapter.map 'Travis.Job', {
|
||||||
repoId: { key: 'repository_id' }
|
repoId: { key: 'repository_id' }
|
||||||
repo: { key: 'repository_id' }
|
repo: { key: 'repository_id' }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Travis.RestAdapter.map 'Travis.User', {
|
||||||
|
_name: { key: 'name' }
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li {{bindAttr class="view.classProfile"}}>
|
<li {{bindAttr class="view.classProfile"}}>
|
||||||
<p class="handle">
|
<p class="handle">
|
||||||
<a class="signed-out" href="#" {{action signIn target="Travis.app"}}>{{t layouts.top.github_login}}</a>
|
<a class="signed-out" href="#" {{action signIn target="Travis"}}>{{t layouts.top.github_login}}</a>
|
||||||
<a class="signed-in" {{action showProfile href=true}}><img {{bindAttr src="view.gravatarUrl"}}>{{view.userName}}</a>
|
<a class="signed-in" {{action showProfile href=true}}><img {{bindAttr src="view.gravatarUrl"}}>{{view.userName}}</a>
|
||||||
<span class="signing-in">{{t layouts.top.signing_in}}</span>
|
<span class="signing-in">{{t layouts.top.signing_in}}</span>
|
||||||
</p>
|
</p>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<a {{action showProfile href=true}}>{{t layouts.top.accounts}}</a>
|
<a {{action showProfile href=true}}>{{t layouts.top.accounts}}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/" {{action signOut target="Travis.app"}}>{{t layouts.top.sign_out}}</a>
|
<a href="/" {{action signOut target="Travis"}}>{{t layouts.top.sign_out}}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
templateName: 'auth/signin'
|
templateName: 'auth/signin'
|
||||||
|
|
||||||
signingIn: (->
|
signingIn: (->
|
||||||
Travis.app.get('authState') == 'signing-in'
|
Travis.get('authState') == 'signing-in'
|
||||||
).property('Travis.app.authState')
|
).property('Travis.authState')
|
||||||
|
|
|
@ -16,10 +16,10 @@ Storage = Em.Object.extend
|
||||||
clear: ->
|
clear: ->
|
||||||
@set('storage', {})
|
@set('storage', {})
|
||||||
|
|
||||||
window.Travis = Em.Application.create Ember.Evented,
|
window.Travis = Em.Application.extend(Ember.Evented,
|
||||||
autoinit: false
|
autoinit: false
|
||||||
currentUserBinding: 'auth.user'
|
|
||||||
authStateBinding: 'auth.state'
|
authStateBinding: 'auth.state'
|
||||||
|
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
|
||||||
|
|
||||||
setup: ->
|
setup: ->
|
||||||
@store = Travis.Store.create(
|
@store = Travis.Store.create(
|
||||||
|
@ -44,7 +44,7 @@ window.Travis = Em.Application.create Ember.Evented,
|
||||||
|
|
||||||
signOut: ->
|
signOut: ->
|
||||||
@get('auth').signOut()
|
@get('auth').signOut()
|
||||||
@get('router').send('afterSignOut')
|
#@get('router').send('afterSignOut')
|
||||||
|
|
||||||
receive: ->
|
receive: ->
|
||||||
@store.receive.apply(@store, arguments)
|
@store.receive.apply(@store, arguments)
|
||||||
|
@ -70,6 +70,8 @@ window.Travis = Em.Application.create Ember.Evented,
|
||||||
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
|
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
|
||||||
I18n.fallbacks = true
|
I18n.fallbacks = true
|
||||||
@setLocale 'locale', @get('defaultLocale')
|
@setLocale 'locale', @get('defaultLocale')
|
||||||
|
@autoSignIn() unless @get('signedIn')
|
||||||
|
).create()
|
||||||
|
|
||||||
$.extend Travis,
|
$.extend Travis,
|
||||||
config:
|
config:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user