mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
#18625: Fixing "Remember Me" checkbox
Work Item: 18625 --HG-- branch : 1.x
This commit is contained in:
@@ -82,14 +82,14 @@ namespace Orchard.Users.Controllers {
|
||||
[AlwaysAccessible]
|
||||
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
||||
Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
||||
public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl) {
|
||||
public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl, bool rememberMe) {
|
||||
var user = ValidateLogOn(userNameOrEmail, password);
|
||||
if (!ModelState.IsValid) {
|
||||
var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
|
||||
return new ShapeResult(this, shape);
|
||||
}
|
||||
|
||||
_authenticationService.SignIn(user, false);
|
||||
_authenticationService.SignIn(user, rememberMe);
|
||||
foreach (var userEventHandler in _userEventHandlers) {
|
||||
userEventHandler.LoggedIn(user);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,20 @@
|
||||
<fieldset class="login-form group">
|
||||
<legend>@T("Account Information")</legend>
|
||||
<ol>
|
||||
<li>
|
||||
<label for="username-email">@T("Username")</label>
|
||||
@Html.TextBox("userNameOrEmail", "", new { id = "username-email", autofocus = "autofocus" })
|
||||
@Html.ValidationMessage("userNameOrEmail")
|
||||
</li>
|
||||
<li>
|
||||
<label for="password">@T("Password")</label>
|
||||
@Html.Password("password")
|
||||
@Html.ValidationMessage("password")
|
||||
</li>
|
||||
<button class="primaryAction" type="submit">@T("Sign In")</button>
|
||||
<li>
|
||||
<label for="username-email">@T("Username")</label>
|
||||
@Html.TextBox("userNameOrEmail", "", new { id = "username-email", autofocus = "autofocus" })
|
||||
@Html.ValidationMessage("userNameOrEmail")
|
||||
</li>
|
||||
<li>
|
||||
<label for="password">@T("Password")</label>
|
||||
@Html.Password("password")
|
||||
@Html.ValidationMessage("password")
|
||||
</li>
|
||||
<li>
|
||||
@Html.CheckBox("rememberMe", new { id = "remember-me" })<label class="forcheckbox" for="remember-me">@T("Remember Me")</label>
|
||||
</li>
|
||||
</ol>
|
||||
<button class="primaryAction" type="submit">@T("Sign In")</button>
|
||||
</fieldset>
|
||||
}
|
||||
@@ -20,8 +20,7 @@ namespace Orchard.Security.Providers {
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
|
||||
// TEMP: who can say...
|
||||
ExpirationTimeSpan = TimeSpan.FromHours(6);
|
||||
ExpirationTimeSpan = TimeSpan.FromDays(30);
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
@@ -31,7 +30,7 @@ namespace Orchard.Security.Providers {
|
||||
public void SignIn(IUser user, bool createPersistentCookie) {
|
||||
var now = _clock.UtcNow.ToLocalTime();
|
||||
var userData = Convert.ToString(user.Id);
|
||||
|
||||
|
||||
var ticket = new FormsAuthenticationTicket(
|
||||
1 /*version*/,
|
||||
user.UserName,
|
||||
@@ -50,7 +49,11 @@ namespace Orchard.Security.Providers {
|
||||
if (FormsAuthentication.CookieDomain != null) {
|
||||
cookie.Domain = FormsAuthentication.CookieDomain;
|
||||
}
|
||||
|
||||
|
||||
if (createPersistentCookie) {
|
||||
cookie.Expires = ticket.Expiration;
|
||||
}
|
||||
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
httpContext.Response.Cookies.Add(cookie);
|
||||
_signedInUser = user;
|
||||
|
||||
Reference in New Issue
Block a user