Support for browser password managers, but doesn't quite work in IE

This commit is contained in:
Neil Lalonde 2013-03-13 10:22:56 -04:00
parent ea20993bed
commit 58004d44cd
5 changed files with 31 additions and 2 deletions

View File

@ -25,7 +25,7 @@
{{i18n login.or}}
</h3>
<form id='login-form'>
<div>
<div>
<table>
<tr>
<td>

View File

@ -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) {

View File

@ -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

View File

@ -21,6 +21,15 @@
</head>
<body>
<% unless current_user %>
<form id='hidden-login-form' method="post" action="/login" style="display: none;">
<input name="username" type="text" id="signin_username">
<input name="password" type="password" id="signin_password">
<input name="redirect" type="hidden">
<input type="submit" id="signin-button" value="Log In">
</form>
<% end %>
<%=SiteCustomization.custom_header(session[:preview_style])%>
<section id='main'>
<section id='loading-message' style='display:none'><%= t :loading %>...</section>

View File

@ -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'