diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 index 152aabadde9..172bd050e27 100644 --- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 +++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 @@ -87,6 +87,7 @@ export default function() { this.route('signup', {path: '/signup'}); this.route('login', {path: '/login'}); + this.route('login-preferences'); this.route('forgot-password', {path: '/password-reset'}); this.route('faq', {path: '/faq'}); this.route('tos', {path: '/tos'}); diff --git a/app/assets/javascripts/discourse/routes/build-static-route.js.es6 b/app/assets/javascripts/discourse/routes/build-static-route.js.es6 new file mode 100644 index 00000000000..eab6d406228 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/build-static-route.js.es6 @@ -0,0 +1,18 @@ +import DiscourseRoute from 'discourse/routes/discourse'; + +export default function(pageName) { + const route = { + model() { + return Discourse.StaticPage.find(pageName); + }, + + renderTemplate() { + this.render('static'); + }, + + setupController(controller, model) { + this.controllerFor('static').set('model', model); + } + }; + return DiscourseRoute.extend(route); +} diff --git a/app/assets/javascripts/discourse/routes/forgot-password.js.es6 b/app/assets/javascripts/discourse/routes/forgot-password.js.es6 index 3985fa1b1a3..df8ab36145b 100644 --- a/app/assets/javascripts/discourse/routes/forgot-password.js.es6 +++ b/app/assets/javascripts/discourse/routes/forgot-password.js.es6 @@ -1,22 +1,13 @@ -export default Discourse.Route.extend({ - beforeModel: function() { - this.replaceWith(this.controllerFor('application').get('loginRequired') ? 'login' : 'discovery').then(function(e) { - Ember.run.next(function() { - e.send('showForgotPassword'); - }); +import buildStaticRoute from 'discourse/routes/build-static-route'; + +const ForgotPasswordRoute = buildStaticRoute('password-reset'); + +ForgotPasswordRoute.reopen({ + beforeModel() { + this.replaceWith(this.controllerFor('application').get('loginRequired') ? 'login' : 'discovery').then(e => { + Ember.run.next(() => e.send('showForgotPassword')); }); }, - - model: function() { - return Discourse.StaticPage.find('password-reset'); - }, - - renderTemplate: function() { - // do nothing - this.render('static'); - }, - - setupController: function(controller, model) { - this.controllerFor('static').set('model', model); - } }); + +export default ForgotPasswordRoute; diff --git a/app/assets/javascripts/discourse/routes/login.js.es6 b/app/assets/javascripts/discourse/routes/login.js.es6 index 36498f6accd..ad8e840f1a1 100644 --- a/app/assets/javascripts/discourse/routes/login.js.es6 +++ b/app/assets/javascripts/discourse/routes/login.js.es6 @@ -1,24 +1,15 @@ -export default Discourse.Route.extend({ - beforeModel: function() { - if (!Discourse.SiteSettings.login_required) { - this.replaceWith('discovery.latest').then(function(e) { - Ember.run.next(function() { - e.send('showLogin'); - }); +import buildStaticRoute from 'discourse/routes/build-static-route'; + +const LoginRoute = buildStaticRoute('login'); + +LoginRoute.reopen({ + beforeModel() { + if (!this.siteSettings.login_required) { + this.replaceWith('discovery.latest').then(e => { + Ember.run.next(() => e.send('showLogin')); }); } - }, - - model: function() { - return Discourse.StaticPage.find('login'); - }, - - renderTemplate: function() { - // do nothing - this.render('static'); - }, - - setupController: function(controller, model) { - this.controllerFor('static').set('model', model); } }); + +export default LoginRoute; diff --git a/app/assets/javascripts/discourse/templates/login-preferences.hbs b/app/assets/javascripts/discourse/templates/login-preferences.hbs new file mode 100644 index 00000000000..6c2db36aa66 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/login-preferences.hbs @@ -0,0 +1,8 @@ +
+

{{i18n "login.to_continue"}}

+ +

{{i18n "login.preferences"}}

+ + {{d-button class="btn-primary" action="showLogin" label="log_in"}} + {{d-button action="showForgotPassword" label="login.forgot"}} +
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0131fcb8094..eb28b8cb18c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -167,7 +167,7 @@ class UsersController < ApplicationController if current_user.blank? cookies[:destination_url] = "/my/#{params[:path]}" - redirect_to :login + redirect_to "/login-preferences" else redirect_to(path("/users/#{current_user.username}/#{params[:path]}")) end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0386bc7c1ea..c86a56ea08b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -807,6 +807,9 @@ en: admin_not_allowed_from_ip_address: "You can't log in as admin from that IP address." resend_activation_email: "Click here to send the activation email again." sent_activation_email_again: "We sent another activation email to you at {{currentEmail}}. It might take a few minutes for it to arrive; be sure to check your spam folder." + to_continue: "Please Log In" + preferences: "You need to be logged in to change your user preferences." + forgot: "I don't recall my account details" google: title: "with Google" message: "Authenticating with Google (make sure pop up blockers are not enabled)" diff --git a/config/routes.rb b/config/routes.rb index c65d39004c9..471b42b2745 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -241,6 +241,7 @@ Discourse::Application.routes.draw do get "tos" => "static#show", id: "tos", as: 'tos' get "privacy" => "static#show", id: "privacy", as: 'privacy' get "signup" => "list#latest" + get "login-preferences" => "static#show", id: "login" get "users/admin-login" => "users#admin_login" put "users/admin-login" => "users#admin_login" diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 164029254ce..e693da0225d 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1430,10 +1430,10 @@ describe UsersController do describe '.my_redirect' do - it "returns 404 if the user is not logged in" do + it "redirects if the user is not logged in" do get :my_redirect, path: "wat" expect(response).not_to be_success - expect(response).not_to be_redirect + expect(response).to be_redirect end context "when the user is logged in" do