diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index e4c2cd6bc01..bbed56d36b8 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -1,6 +1,15 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import DiscourseController from 'discourse/controllers/controller'; +// This is happening outside of the app via popup +function showModal(modal) { + const route = Discourse.__container__.lookup('route:application'); + Discourse.Route.showModal(route, modal); +} +const AuthErrors = + ['requires_invite', 'awaiting_approval', 'awaiting_confirmation', 'admin_not_allowed_from_ip_address', + 'not_allowed_from_ip_address']; + export default DiscourseController.extend(ModalFunctionality, { needs: ['modal', 'createAccount', 'forgotPassword', 'application'], authenticate: null, @@ -146,42 +155,27 @@ export default DiscourseController.extend(ModalFunctionality, { }).property('authenticate'), authenticationComplete: function(options) { - if (options.requires_invite) { - this.send('showLogin'); - this.flash(I18n.t('login.requires_invite'), 'success'); - this.set('authenticate', null); - return; + + const self = this; + function loginError(errorMsg, className) { + showModal('login'); + Ember.run.next(function() { + self.flash(errorMsg, className || 'success'); + self.set('authenticate', null); + }); } - if (options.awaiting_approval) { - this.send('showLogin'); - this.flash(I18n.t('login.awaiting_approval'), 'success'); - this.set('authenticate', null); - return; - } - if (options.awaiting_activation) { - this.send('showLogin'); - this.flash(I18n.t('login.awaiting_confirmation'), 'success'); - this.set('authenticate', null); - return; - } - if (options.admin_not_allowed_from_ip_address) { - this.send('showLogin'); - this.flash(I18n.t('login.admin_not_allowed_from_ip_address'), 'success'); - this.set('authenticate', null); - return; - } - if (options.not_allowed_from_ip_address) { - this.send('showLogin'); - this.flash(I18n.t('login.not_allowed_from_ip_address'), 'success'); - this.set('authenticate', null); - return; + + for (let i=0; i this.controllerFor('login').resetForm()); } }, handleShowCreateAccount() { - const self = this; + this._autoLogin('createAccount'); + }, + + _autoLogin(modal, notAuto) { + const methods = Em.get('Discourse.LoginMethod.all'); + if (!this.siteSettings.enable_local_logins && methods.length === 1) { + this.controllerFor('login').send('externalLogin', methods[0]); + } else { + Discourse.Route.showModal(this, modal); + if (notAuto) { notAuto(); } + } + }, - self.send('autoLogin', 'createAccount', function(){ - Discourse.Route.showModal(self, 'createAccount'); - }); - } }); RSVP.EventTarget.mixin(ApplicationRoute); diff --git a/app/assets/javascripts/discourse/routes/discourse_route.js b/app/assets/javascripts/discourse/routes/discourse_route.js index 8f0cc516aa5..926c457ea7b 100644 --- a/app/assets/javascripts/discourse/routes/discourse_route.js +++ b/app/assets/javascripts/discourse/routes/discourse_route.js @@ -197,15 +197,10 @@ Discourse.Route.reopenClass({ appEvents.trigger('dom:clean'); }, - /** - Shows a modal - - @method showModal - **/ - showModal: function(router, name, model) { - router.controllerFor('modal').set('modalClass', null); - router.render(name, {into: 'modal', outlet: 'modalBody'}); - var controller = router.controllerFor(name); + showModal: function(route, name, model) { + route.controllerFor('modal').set('modalClass', null); + route.render(name, {into: 'modal', outlet: 'modalBody'}); + var controller = route.controllerFor(name); if (controller) { if (model) { controller.set('model', model);