From 985b356fe937643be8e33c2880b04d65c8e2dc9a Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 14 Aug 2014 15:13:11 +1000 Subject: [PATCH] FIX: work better if there is only one LoginMethod If there is only 1 login method and local logins are disabled take user directly to the login provider --- .../discourse/routes/application.js.es6 | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index 4225c1b686a..72484332d02 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -23,6 +23,8 @@ var ApplicationRoute = Em.Route.extend({ }, showLogin: function() { + var self = this; + if (Discourse.get("isReadOnly")) { bootbox.alert(I18n.t("read_only_mode.login_disabled")); } else { @@ -30,14 +32,31 @@ var ApplicationRoute = Em.Route.extend({ var returnPath = encodeURIComponent(window.location.pathname); window.location = Discourse.getURL('/session/sso?return_path=' + returnPath); } else { - Discourse.Route.showModal(this, 'login'); - this.controllerFor('login').resetForm(); + this.send('autoLogin', function(){ + Discourse.Route.showModal(self, 'login'); + self.controllerFor('login').resetForm(); + }); } } }, showCreateAccount: function() { - Discourse.Route.showModal(this, 'createAccount'); + var self = this; + + self.send('autoLogin', function(){ + Discourse.Route.showModal(self, 'createAccount'); + }); + }, + + autoLogin: function(onFail){ + var methods = Em.get('Discourse.LoginMethod.all'); + if (!Discourse.SiteSettings.enable_local_logins && + methods.length === 1) { + Discourse.Route.showModal(this, 'login'); + this.controllerFor('login').send("externalLogin", methods[0]); + } else { + onFail(); + } }, showForgotPassword: function() {