Skip to content

Instantly share code, notes, and snippets.

@Blackmist
Created May 15, 2013 19:03
Show Gist options
  • Save Blackmist/5586431 to your computer and use it in GitHub Desktop.
Save Blackmist/5586431 to your computer and use it in GitHub Desktop.
controllers that talk to loginstate
//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");
}
});
// 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