mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-04 18:03:59 -04:00
Support for browser password managers, but doesn't quite work in IE
This commit is contained in:
parent
ea20993bed
commit
58004d44cd
5 changed files with 31 additions and 2 deletions
app
assets/javascripts/discourse
controllers
views/layouts
config
|
@ -25,7 +25,7 @@
|
||||||
{{i18n login.or}}
|
{{i18n login.or}}
|
||||||
</h3>
|
</h3>
|
||||||
<form id='login-form'>
|
<form id='login-form'>
|
||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -56,7 +56,11 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
|
||||||
}
|
}
|
||||||
_this.flash(result.error, 'error');
|
_this.flash(result.error, 'error');
|
||||||
} else {
|
} 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) {
|
}).fail(function(result) {
|
||||||
_this.flash(Em.String.i18n('login.error'), 'error');
|
_this.flash(Em.String.i18n('login.error'), 'error');
|
||||||
|
@ -143,6 +147,11 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement: function(e) {
|
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;
|
var _this = this;
|
||||||
return Em.run.next(function() {
|
return Em.run.next(function() {
|
||||||
return $('#login-account-password').keydown(function(e) {
|
return $('#login-account-password').keydown(function(e) {
|
||||||
|
|
|
@ -24,4 +24,14 @@ class StaticController < ApplicationController
|
||||||
render file: 'public/404', layout: false, status: 404
|
render file: 'public/404', layout: false, status: 404
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -21,6 +21,15 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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])%>
|
<%=SiteCustomization.custom_header(session[:preview_style])%>
|
||||||
<section id='main'>
|
<section id='main'>
|
||||||
<section id='loading-message' style='display:none'><%= t :loading %>...</section>
|
<section id='loading-message' style='display:none'><%= t :loading %>...</section>
|
||||||
|
|
|
@ -76,6 +76,7 @@ Discourse::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :static
|
resources :static
|
||||||
|
post 'login' => 'static#enter'
|
||||||
get 'faq' => 'static#show', id: 'faq'
|
get 'faq' => 'static#show', id: 'faq'
|
||||||
get 'tos' => 'static#show', id: 'tos'
|
get 'tos' => 'static#show', id: 'tos'
|
||||||
get 'privacy' => 'static#show', id: 'privacy'
|
get 'privacy' => 'static#show', id: 'privacy'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue