增加功能:选中记住我自动登录后,系统默认7天内有效
This commit is contained in:
parent
3ffb84a67c
commit
93904c70f0
|
@ -1,9 +1,12 @@
|
||||||
using Bootstrap.Admin.Models;
|
using Bootstrap.Admin.Models;
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Configuration;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -24,7 +27,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult Login()
|
public ActionResult Login()
|
||||||
{
|
{
|
||||||
return View("Login", new ModelBase());
|
return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View("Login", new ModelBase());
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Login the specified userName, password and remember.
|
/// Login the specified userName, password and remember.
|
||||||
|
@ -40,7 +43,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
{
|
{
|
||||||
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
|
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
|
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
|
// redirect origin url
|
||||||
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";
|
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"AllowOrigins": "http://localhost,http://10.15.63.218",
|
"AllowOrigins": "http://localhost,http://10.15.63.218",
|
||||||
"KeepExceptionsPeriod": 12,
|
"KeepExceptionsPeriod": 12,
|
||||||
"KeepLogsPeriod": 12,
|
"KeepLogsPeriod": 12,
|
||||||
|
"CookieExpiresDays": 7,
|
||||||
"LongbowCache": {
|
"LongbowCache": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"CorsItems": [
|
"CorsItems": [
|
||||||
|
|
Loading…
Reference in New Issue