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