Refactor sign in related templates, fix indicator in auth template
This commit is contained in:
parent
218a078164
commit
c79725d0e9
|
@ -1,7 +1,7 @@
|
|||
unless window.TravisApplication
|
||||
window.TravisApplication = Em.Application.extend(Ember.Evented,
|
||||
LOG_TRANSITIONS: true,
|
||||
authStateBinding: 'auth.state'
|
||||
authState: Ember.computed.alias('auth.state')
|
||||
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
|
||||
|
||||
mappings: (->
|
||||
|
@ -58,6 +58,10 @@ unless window.TravisApplication
|
|||
signOut: ->
|
||||
@get('auth').signOut()
|
||||
|
||||
signingIn: (->
|
||||
Travis.get('authState') == 'signing-in'
|
||||
).property('authState')
|
||||
|
||||
receive: (event, data) ->
|
||||
[name, type] = event.split(':')
|
||||
|
||||
|
|
|
@ -5,6 +5,26 @@ Travis.TopController = Em.Controller.extend
|
|||
needs: ['currentUser']
|
||||
userBinding: 'controllers.currentUser'
|
||||
|
||||
userName: (->
|
||||
@get('user.name') || @get('user.login')
|
||||
).property('user.login', 'user.name')
|
||||
|
||||
gravatarUrl: (->
|
||||
"#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=48&d=mm"
|
||||
).property('user.gravatarId')
|
||||
|
||||
signedIn: (->
|
||||
Travis.get('authState') == 'signed-in'
|
||||
).property('Travis.authState')
|
||||
|
||||
signedOut: (->
|
||||
Travis.get('authState') == 'signed-out'
|
||||
).property('Travis.authState')
|
||||
|
||||
signingIn: (->
|
||||
Travis.get('authState') == 'signing-in'
|
||||
).property('Travis.authState')
|
||||
|
||||
Travis.ApplicationController = Em.Controller.extend
|
||||
templateName: 'layouts/home'
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ Ember.Route.reopen
|
|||
|
||||
error: (error) ->
|
||||
if error == 'needs-auth'
|
||||
authController = @container.lookup('controller:auth') || @generateController('auth')
|
||||
authController.set('redirected', true)
|
||||
@transitionTo('auth')
|
||||
else
|
||||
throw(error)
|
||||
|
@ -384,3 +386,6 @@ Travis.AuthRoute = Ember.Route.extend
|
|||
|
||||
setupController: ->
|
||||
@container.lookup('controller:application').connectLayout('simple')
|
||||
|
||||
deactivate: ->
|
||||
@controllerFor('auth').set('redirected', false)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{{#if view.signingIn}}
|
||||
<h1>Signing in ...</h1>
|
||||
<p>
|
||||
Trying to authenticate with GitHub.
|
||||
</p>
|
||||
{{else}}
|
||||
<h1>Sign in</h1>
|
||||
<p>
|
||||
<a href="#" {{action "signIn" target="Travis"}}>Please sign in with GitHub.</a>
|
||||
</p>
|
||||
{{#if redirected}}
|
||||
<p>You need to sign in to see this page.</p>
|
||||
{{/if}}
|
||||
<p>
|
||||
<a href="#" {{action "signIn" target="Travis"}}>
|
||||
{{#if Travis.signingIn}}
|
||||
Signing in...
|
||||
{{else}}
|
||||
Sign in with GitHub.
|
||||
{{/if}}
|
||||
</a>
|
||||
</p>
|
||||
|
|
|
@ -31,9 +31,15 @@
|
|||
</li>
|
||||
<li {{bindAttr class="view.classProfile"}}>
|
||||
<p class="handle">
|
||||
{{#if signedOut}}
|
||||
<a class="signed-out" href="#" {{action "signIn" target="Travis"}}>{{t layouts.top.github_login}}</a>
|
||||
{{#linkTo "profile.index" class="signed-in"}}<img {{bindAttr src="view.gravatarUrl"}}>{{view.userName}}{{/linkTo}}
|
||||
{{/if}}
|
||||
{{#if signedIn}}
|
||||
{{#linkTo "profile.index" class="signed-in"}}<img {{bindAttr src="gravatarUrl"}}/>{{userName}}{{/linkTo}}
|
||||
{{/if}}
|
||||
{{#if signingIn}}
|
||||
<span class="signing-in">{{t layouts.top.signing_in}}</span>
|
||||
{{/if}}
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
|
|
|
@ -3,15 +3,6 @@
|
|||
templateName: 'layouts/top'
|
||||
|
||||
tabBinding: 'controller.tab'
|
||||
userBinding: 'controller.user'
|
||||
|
||||
userName: (->
|
||||
@get('user.name') || @get('user.login')
|
||||
).property('user.login', 'user.name')
|
||||
|
||||
gravatarUrl: (->
|
||||
"#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=48&d=mm"
|
||||
).property('user.gravatarId')
|
||||
|
||||
# hrm. how to parametrize bindAttr?
|
||||
classHome: (->
|
||||
|
@ -25,7 +16,7 @@
|
|||
classProfile: (->
|
||||
classes = ['profile menu']
|
||||
classes.push('active') if @get('tab') == 'profile'
|
||||
classes.push(Travis.get('authState'))
|
||||
classes.push(Travis.get('authState') || 'signed-out')
|
||||
classes.join(' ')
|
||||
).property('tab', 'Travis.authState')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user