From eb473696fffa93ebaa0766cb4f97d88d9ccf98a2 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 2 Oct 2014 17:27:41 -0400 Subject: [PATCH] Refactor showLogin and showCreateAccount actions for extensibility --- .../discourse/routes/application.js.es6 | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index fbafb966f03..a2058ca0c64 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -39,29 +39,15 @@ var ApplicationRoute = Em.Route.extend({ }, showLogin: function() { - var self = this; - if (this.site.get("isReadOnly")) { bootbox.alert(I18n.t("read_only_mode.login_disabled")); } else { - 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(); - }); - } + this.handleShowLogin(); } }, showCreateAccount: function() { - var self = this; - - self.send('autoLogin', 'createAccount', function(){ - Discourse.Route.showModal(self, 'createAccount'); - }); + this.handleShowCreateAccount(); }, autoLogin: function(modal, onFail){ @@ -159,8 +145,29 @@ var ApplicationRoute = Em.Route.extend({ // Support for callbacks once the application has activated 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);