UX: Show a nicer "Log In" screen if the user follows /my/preferences

This commit is contained in:
Robin Ward 2015-10-14 13:39:31 -04:00
parent d66a545dd2
commit a527c58c7d
9 changed files with 55 additions and 42 deletions

View file

@ -87,6 +87,7 @@ export default function() {
this.route('signup', {path: '/signup'}); this.route('signup', {path: '/signup'});
this.route('login', {path: '/login'}); this.route('login', {path: '/login'});
this.route('login-preferences');
this.route('forgot-password', {path: '/password-reset'}); this.route('forgot-password', {path: '/password-reset'});
this.route('faq', {path: '/faq'}); this.route('faq', {path: '/faq'});
this.route('tos', {path: '/tos'}); this.route('tos', {path: '/tos'});

View file

@ -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);
}

View file

@ -1,22 +1,13 @@
export default Discourse.Route.extend({ import buildStaticRoute from 'discourse/routes/build-static-route';
beforeModel: function() {
this.replaceWith(this.controllerFor('application').get('loginRequired') ? 'login' : 'discovery').then(function(e) { const ForgotPasswordRoute = buildStaticRoute('password-reset');
Ember.run.next(function() {
e.send('showForgotPassword'); 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;

View file

@ -1,24 +1,15 @@
export default Discourse.Route.extend({ import buildStaticRoute from 'discourse/routes/build-static-route';
beforeModel: function() {
if (!Discourse.SiteSettings.login_required) { const LoginRoute = buildStaticRoute('login');
this.replaceWith('discovery.latest').then(function(e) {
Ember.run.next(function() { LoginRoute.reopen({
e.send('showLogin'); 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;

View file

@ -0,0 +1,8 @@
<div class='container'>
<h2>{{i18n "login.to_continue"}}</h2>
<p style='margin-top: 1em'>{{i18n "login.preferences"}}</p>
{{d-button class="btn-primary" action="showLogin" label="log_in"}}
{{d-button action="showForgotPassword" label="login.forgot"}}
</div>

View file

@ -167,7 +167,7 @@ class UsersController < ApplicationController
if current_user.blank? if current_user.blank?
cookies[:destination_url] = "/my/#{params[:path]}" cookies[:destination_url] = "/my/#{params[:path]}"
redirect_to :login redirect_to "/login-preferences"
else else
redirect_to(path("/users/#{current_user.username}/#{params[:path]}")) redirect_to(path("/users/#{current_user.username}/#{params[:path]}"))
end end

View file

@ -807,6 +807,9 @@ en:
admin_not_allowed_from_ip_address: "You can't log in as admin from that IP address." 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." resend_activation_email: "Click here to send the activation email again."
sent_activation_email_again: "We sent another activation email to you at <b>{{currentEmail}}</b>. It might take a few minutes for it to arrive; be sure to check your spam folder." sent_activation_email_again: "We sent another activation email to you at <b>{{currentEmail}}</b>. 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: google:
title: "with Google" title: "with Google"
message: "Authenticating with Google (make sure pop up blockers are not enabled)" message: "Authenticating with Google (make sure pop up blockers are not enabled)"

View file

@ -241,6 +241,7 @@ Discourse::Application.routes.draw do
get "tos" => "static#show", id: "tos", as: 'tos' get "tos" => "static#show", id: "tos", as: 'tos'
get "privacy" => "static#show", id: "privacy", as: 'privacy' get "privacy" => "static#show", id: "privacy", as: 'privacy'
get "signup" => "list#latest" get "signup" => "list#latest"
get "login-preferences" => "static#show", id: "login"
get "users/admin-login" => "users#admin_login" get "users/admin-login" => "users#admin_login"
put "users/admin-login" => "users#admin_login" put "users/admin-login" => "users#admin_login"

View file

@ -1430,10 +1430,10 @@ describe UsersController do
describe '.my_redirect' 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" get :my_redirect, path: "wat"
expect(response).not_to be_success expect(response).not_to be_success
expect(response).not_to be_redirect expect(response).to be_redirect
end end
context "when the user is logged in" do context "when the user is logged in" do