From 58004d44cd299e39bf4648645529218d59577ded Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 13 Mar 2013 10:22:56 -0400 Subject: [PATCH] Support for browser password managers, but doesn't quite work in IE --- .../discourse/templates/modal/login.js.handlebars | 2 +- .../javascripts/discourse/views/modal/login_view.js | 11 ++++++++++- app/controllers/static_controller.rb | 10 ++++++++++ app/views/layouts/application.html.erb | 9 +++++++++ config/routes.rb | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/modal/login.js.handlebars b/app/assets/javascripts/discourse/templates/modal/login.js.handlebars index ae1bfec7dc3..b608acdc754 100644 --- a/app/assets/javascripts/discourse/templates/modal/login.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/login.js.handlebars @@ -25,7 +25,7 @@ {{i18n login.or}}
-
+
diff --git a/app/assets/javascripts/discourse/views/modal/login_view.js b/app/assets/javascripts/discourse/views/modal/login_view.js index 05d662bc650..b510260b592 100644 --- a/app/assets/javascripts/discourse/views/modal/login_view.js +++ b/app/assets/javascripts/discourse/views/modal/login_view.js @@ -56,7 +56,11 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({ } _this.flash(result.error, 'error'); } else { - return window.location.reload(); + // Trigger the browser's password manager using the hidden static login form: + $('#hidden-login-form input[name=username]').val(_this.get('loginName')); + $('#hidden-login-form input[name=password]').val(_this.get('loginPassword')); + $('#hidden-login-form input[name=redirect]').val(window.location.href); + $('#hidden-login-form').submit(); } }).fail(function(result) { _this.flash(Em.String.i18n('login.error'), 'error'); @@ -143,6 +147,11 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({ }, didInsertElement: function(e) { + // Get username and password from the browser's password manager, + // if it filled the hidden static login form: + this.set('loginName', $('#hidden-login-form input[name=username]').val()); + this.set('loginPassword', $('#hidden-login-form input[name=password]').val()); + var _this = this; return Em.run.next(function() { return $('#login-account-password').keydown(function(e) { diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 63e6e7e8690..87386d1ce6b 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -24,4 +24,14 @@ class StaticController < ApplicationController render file: 'public/404', layout: false, status: 404 end + # This method just redirects to a given url. + # It's used when an ajax login was successful but we want the browser to see + # a post of a login form so that it offers to remember your password. + def enter + params.delete(:username) + params.delete(:password) + redirect_to(params[:redirect] || '/') + end + + end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 739fa52d0ae..b4d310386d4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -21,6 +21,15 @@ + <% unless current_user %> + + + + + + + <% end %> + <%=SiteCustomization.custom_header(session[:preview_style])%>
diff --git a/config/routes.rb b/config/routes.rb index 299e2606f58..746aa06690f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,6 +76,7 @@ Discourse::Application.routes.draw do end resources :static + post 'login' => 'static#enter' get 'faq' => 'static#show', id: 'faq' get 'tos' => 'static#show', id: 'tos' get 'privacy' => 'static#show', id: 'privacy'