增加功能:选中记住我自动登录后,系统默认7天内有效

This commit is contained in:
Argo-MacBookPro 2018-09-26 17:57:07 +08:00
parent 3ffb84a67c
commit 93904c70f0
2 changed files with 6 additions and 2 deletions

View File

@ -1,9 +1,12 @@
using Bootstrap.Admin.Models;
using Bootstrap.Security;
using Longbow;
using Longbow.Configuration;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
@ -24,7 +27,7 @@ namespace Bootstrap.Admin.Controllers
[HttpGet]
public ActionResult Login()
{
return View("Login", new ModelBase());
return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View("Login", new ModelBase());
}
/// <summary>
/// Login the specified userName, password and remember.
@ -40,7 +43,7 @@ namespace Bootstrap.Admin.Controllers
{
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties() { IsPersistent = remember == "true" });
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties() { ExpiresUtc = DateTimeOffset.Now.AddDays(LgbConvert.ReadValue(ConfigurationManager.AppSettings["CookieExpiresDays"], 7)), IsPersistent = remember == "true" });
}
// redirect origin url
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";

View File

@ -29,6 +29,7 @@
"AllowOrigins": "http://localhost,http://10.15.63.218",
"KeepExceptionsPeriod": 12,
"KeepLogsPeriod": 12,
"CookieExpiresDays": 7,
"LongbowCache": {
"Enabled": true,
"CorsItems": [