Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2013 14:31
Show Gist options
  • Save anonymous/4648597 to your computer and use it in GitHub Desktop.
Save anonymous/4648597 to your computer and use it in GitHub Desktop.
window.App = Em.Application.create({
LOG_TRANSITIONS: true
});
App.deferReadiness();
App.Router.map(function() {
this.route("login", { path: "/login" });
this.route("explore", { path: "/explore" });
this.route("events", { path: "/events" });
});
App.LoginView = Ember.View.extend({
didInsertElement : function(){
FB.XFBML.parse();
}
});
App.LoginController = Ember.ObjectController.extend({
authenticated: false,
authenticateFor : "",
init : function(){
FB.Event.subscribe('auth.authResponseChange', function(response) {
// I can't reach to loginController
App.loginController.authenticate();
});
},
authenticate : function(){
this.set("authenticated",true);
this.transitionTo(this.get("authenticateFor"));
},
deauthenticate : function(){
this.set("authenticated",false);
this.transitionTo("index");
}
});
App.AuthRoute = Ember.Route.extend({
redirect : function() {
if (!this.controllerFor('login').get("authenticated")){
this.controllerFor('login').set("authenticateFor",this.routeName);
this.transitionTo('login');
}
}
});
App.EventsRoute = App.AuthRoute.extend();
App.advanceReadiness();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment