Refactor showLogin and showCreateAccount actions for extensibility

This commit is contained in:
Neil Lalonde 2014-10-02 17:27:41 -04:00
parent ebf46450bc
commit eb473696ff
1 changed files with 24 additions and 17 deletions

View File

@ -39,29 +39,15 @@ var ApplicationRoute = Em.Route.extend({
}, },
showLogin: function() { showLogin: function() {
var self = this;
if (this.site.get("isReadOnly")) { if (this.site.get("isReadOnly")) {
bootbox.alert(I18n.t("read_only_mode.login_disabled")); bootbox.alert(I18n.t("read_only_mode.login_disabled"));
} else { } else {
if(Discourse.SiteSettings.enable_sso) { this.handleShowLogin();
var returnPath = encodeURIComponent(window.location.pathname);
window.location = Discourse.getURL('/session/sso?return_path=' + returnPath);
} else {
this.send('autoLogin', 'login', function(){
Discourse.Route.showModal(self, 'login');
self.controllerFor('login').resetForm();
});
}
} }
}, },
showCreateAccount: function() { showCreateAccount: function() {
var self = this; this.handleShowCreateAccount();
self.send('autoLogin', 'createAccount', function(){
Discourse.Route.showModal(self, 'createAccount');
});
}, },
autoLogin: function(modal, onFail){ autoLogin: function(modal, onFail){
@ -159,8 +145,29 @@ var ApplicationRoute = Em.Route.extend({
// Support for callbacks once the application has activated // Support for callbacks once the application has activated
ApplicationRoute.trigger('activate'); ApplicationRoute.trigger('activate');
}); });
} },
handleShowLogin: function() {
var self = this;
if(Discourse.SiteSettings.enable_sso) {
var returnPath = encodeURIComponent(window.location.pathname);
window.location = Discourse.getURL('/session/sso?return_path=' + returnPath);
} else {
this.send('autoLogin', 'login', function(){
Discourse.Route.showModal(self, 'login');
self.controllerFor('login').resetForm();
});
}
},
handleShowCreateAccount: function() {
var self = this;
self.send('autoLogin', 'createAccount', function(){
Discourse.Route.showModal(self, 'createAccount');
});
}
}); });
RSVP.EventTarget.mixin(ApplicationRoute); RSVP.EventTarget.mixin(ApplicationRoute);