Created
May 15, 2013 19:03
-
-
Save Blackmist/5586431 to your computer and use it in GitHub Desktop.
controllers that talk to loginstate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Application controller, since we want login to be an application wide thing | |
//login/logout events are bubbled up to here regardless of the page you are on | |
App.ApplicationController = Em.Controller.extend({ | |
authStateBinding: Ember.Binding.oneWay('App.LoginStateManager.currentState.name'), | |
authState: null, | |
isAuthenticated: function () { | |
return (this.get('authState') == 'isAuthenticated'); | |
}.property('authState'), | |
login: function(provider) { | |
client.login(provider).then(function(results) { | |
App.LoginStateManager.send("login", client.currentUser); | |
}); | |
}, | |
logout: function() { | |
client.logout(); | |
App.LoginStateManager.send("logout"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Newpost controller | |
App.NewpostController = Ember.ObjectController.extend({ | |
title: '', | |
body: '', | |
authStateBinding: Ember.Binding.oneWay('App.LoginStateManager.currentState.name'), | |
authState: null, | |
isAuthenticated: function () { | |
return (this.get('authState') == 'isAuthenticated'); | |
}.property('authState'), | |
save: function() { | |
//create the post | |
var now = new Date(); | |
var post=App.Post.create({ | |
title: this.get('title'), | |
body: this.get('body'), | |
posted: now.toString('dddd, MMMM, yyyy'), | |
}); | |
post.save(); | |
// set these back to '' so the form is pretty | |
this.set('title',''); | |
this.set('body',''); | |
//transition back to posts | |
this.transitionToRoute('posts'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment