From 7f6b2e5563b4808b2b1413dd117d0fea8d33d3ca Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 18 Feb 2014 17:18:42 -0500 Subject: [PATCH] Show login button on 404 page. Add routes to show login and signup modals when page/route loads. If logged in and showing 404 page, load ember app. --- .../discourse/routes/application_routes.js | 4 ++++ .../javascripts/discourse/routes/login_route.js | 11 +++++++++++ .../javascripts/discourse/routes/signup_route.js | 9 +++++++++ .../javascripts/discourse/routes/static_route.js | 12 ++++++++++++ app/controllers/application_controller.rb | 2 +- app/views/layouts/no_js.html.erb | 5 +++++ app/views/static/login.html.erb | 4 +++- config/locales/server.en.yml | 1 + config/routes.rb | 3 ++- 9 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/discourse/routes/login_route.js create mode 100644 app/assets/javascripts/discourse/routes/signup_route.js diff --git a/app/assets/javascripts/discourse/routes/application_routes.js b/app/assets/javascripts/discourse/routes/application_routes.js index b7a33ab405b..0dcc467aeb6 100644 --- a/app/assets/javascripts/discourse/routes/application_routes.js +++ b/app/assets/javascripts/discourse/routes/application_routes.js @@ -8,6 +8,7 @@ Discourse.Route.buildRoutes(function() { var router = this; // Generate static page routes + // e.g., faq, tos, privacy, login _.each(Discourse.StaticController.PAGES, function (page) { router.route(page, { path: '/' + page }); }); @@ -90,4 +91,7 @@ Discourse.Route.buildRoutes(function() { this.route('invited'); }); + + this.route('signup', {path: '/signup'}); + this.route('login', {path: '/login'}); }); diff --git a/app/assets/javascripts/discourse/routes/login_route.js b/app/assets/javascripts/discourse/routes/login_route.js new file mode 100644 index 00000000000..074efb3803e --- /dev/null +++ b/app/assets/javascripts/discourse/routes/login_route.js @@ -0,0 +1,11 @@ +Discourse.LoginRoute = Discourse.Route.extend({ + beforeModel: function() { + if (!Discourse.SiteSetting.login_required) { + this.transitionTo('discovery.latest').then(function(e) { + Ember.run.next(function() { + e.send('showLogin'); + }); + }); + } + } +}); diff --git a/app/assets/javascripts/discourse/routes/signup_route.js b/app/assets/javascripts/discourse/routes/signup_route.js new file mode 100644 index 00000000000..e6a1b77a0fc --- /dev/null +++ b/app/assets/javascripts/discourse/routes/signup_route.js @@ -0,0 +1,9 @@ +Discourse.SignupRoute = Discourse.Route.extend({ + beforeModel: function() { + this.transitionTo('discovery.latest').then(function(e) { + Ember.run.next(function() { + e.send('showCreateAccount'); + }); + }); + } +}); diff --git a/app/assets/javascripts/discourse/routes/static_route.js b/app/assets/javascripts/discourse/routes/static_route.js index 2099a2fe3ec..fd6092abbbc 100644 --- a/app/assets/javascripts/discourse/routes/static_route.js +++ b/app/assets/javascripts/discourse/routes/static_route.js @@ -26,3 +26,15 @@ _.each(Discourse.StaticController.PAGES, function(page) { }); }); + +Discourse.LoginRoute.reopen({ + beforeModel: function() { + if (!Discourse.SiteSettings.login_required) { + this.transitionTo('discovery.latest').then(function(e) { + Ember.run.next(function() { + e.send('showLogin'); + }); + }); + } + } +}); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 091cac0856f..44686a477a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -104,7 +104,7 @@ class ApplicationController < ActionController::Base # from the above rescue_from blocks will fail because that isn't valid json. render status: error, layout: false, text: (error == 404) ? build_not_found_page(error) : message else - render text: build_not_found_page(error, 'no_js') + render text: build_not_found_page(error, current_user ? 'application' : 'no_js') end end diff --git a/app/views/layouts/no_js.html.erb b/app/views/layouts/no_js.html.erb index 871230b50f0..7b86ad3ee7d 100644 --- a/app/views/layouts/no_js.html.erb +++ b/app/views/layouts/no_js.html.erb @@ -24,6 +24,11 @@
+ <% unless current_user %> +
+ <%= I18n.t('log_in') %> +
+ <% end %> diff --git a/app/views/static/login.html.erb b/app/views/static/login.html.erb index 4971cd49c7c..6e840e6e9ab 100644 --- a/app/views/static/login.html.erb +++ b/app/views/static/login.html.erb @@ -1 +1,3 @@ -<%= markdown_content(:login_required_welcome_message) %> +<% if SiteSetting.login_required %> + <%= markdown_content(:login_required_welcome_message) %> +<% end %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 13e1a21a0bd..c4a2c9d78d6 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -20,6 +20,7 @@ en: posts: "posts" loading: "Loading" powered_by_html: 'Powered by Discourse, best viewed with JavaScript enabled' + log_in: "Log In" via: "%{username} via %{site_name}" is_reserved: "is reserved" diff --git a/config/routes.rb b/config/routes.rb index 48228066d6a..81b152f2922 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Discourse::Application.routes.draw do match "/404", to: "exceptions#not_found", via: [:get, :post] mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new - + get "site" => "site#index" resources :forums @@ -155,6 +155,7 @@ Discourse::Application.routes.draw do get "faq" => "static#show", id: "faq" get "tos" => "static#show", id: "tos" get "privacy" => "static#show", id: "privacy" + get "signup" => "list#latest" get "users/search/users" => "users#search_users" get "users/password-reset/:token" => "users#password_reset"