chore
This commit is contained in:
@@ -43,7 +43,7 @@ else
|
||||
</GridCol>
|
||||
</GridRow>
|
||||
<GridRow Style="padding-top:40px">
|
||||
<span style="font-size:12px;padding-right:3px;">Copyright © 2025-@DateTime.Now.Year Atomx.cn All rights reserved.</span>
|
||||
<span style="font-size:12px;padding-right:3px;">Copyright © 2025-@DateTime.Now.Year Atomlust.com All rights reserved.</span>
|
||||
<span style="font-size:12px">runing as @handler</span>
|
||||
</GridRow>
|
||||
</Flex>
|
||||
|
||||
@@ -31,14 +31,17 @@
|
||||
<Flex Justify="FlexJustify.SpaceBetween">
|
||||
帐号列表
|
||||
<div>
|
||||
<AuthorizeView Policy="@Permissions.Admin.Edit">
|
||||
<AuthorizePermissionView Permission="@Permissions.User.Create">
|
||||
<button class="btn btn-primary">创建用户</button>
|
||||
</AuthorizePermissionView>
|
||||
@* <AuthorizeView Policy="@Permissions.Admin.Edit">
|
||||
<Authorized>
|
||||
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
没有权限
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
</AuthorizeView> *@
|
||||
</div>
|
||||
</Flex>
|
||||
</TitleTemplate>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.JSInterop
|
||||
@using Atomx.Admin.Client.Components
|
||||
@using Atomx.Admin.Client
|
||||
@using Atomx.Admin.Client.Services
|
||||
@using Atomx.Admin.Client.Layout
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Admin.Client.Validators;
|
||||
using Atomx.Admin.Services;
|
||||
using Atomx.Admin.Utils;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Common.Utils;
|
||||
using Atomx.Data;
|
||||
@@ -10,12 +11,15 @@ using Atomx.Data.Services;
|
||||
using Atomx.Utils.Extension;
|
||||
using MapsterMapper;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Atomx.Admin.Controllers
|
||||
{
|
||||
@@ -30,8 +34,9 @@ namespace Atomx.Admin.Controllers
|
||||
readonly DataContext _dbContext;
|
||||
readonly JwtSetting _jwtSetting;
|
||||
readonly ICacheService _cacheService;
|
||||
readonly AuthenticationStateProvider _authenticationStateProvider;
|
||||
|
||||
public SignController(ILogger<SignController> logger, IdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService)
|
||||
public SignController(ILogger<SignController> logger, IdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService, AuthenticationStateProvider authenticationStateProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_identityService = identityService;
|
||||
@@ -40,6 +45,7 @@ namespace Atomx.Admin.Controllers
|
||||
_dbContext = dbContext;
|
||||
_jwtSetting = jwtSetting;
|
||||
_cacheService = cacheService;
|
||||
_authenticationStateProvider = authenticationStateProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +54,7 @@ namespace Atomx.Admin.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpPost("in")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Login(LoginModel model)
|
||||
public async Task<IActionResult> Login(LoginModel model)
|
||||
{
|
||||
var validator = new LoginModelValidator();
|
||||
var validation = validator.Validate(model);
|
||||
@@ -100,10 +106,12 @@ namespace Atomx.Admin.Controllers
|
||||
new Claim(ClaimKeys.Permission, role?.Permission??string.Empty)
|
||||
};
|
||||
|
||||
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Subject = claimsIdentity,
|
||||
|
||||
Expires = DateTime.UtcNow.AddMinutes(_jwtSetting.AccessTokenExpirationMinutes),
|
||||
SigningCredentials = credentials,
|
||||
@@ -119,6 +127,9 @@ namespace Atomx.Admin.Controllers
|
||||
user.LastIp = _identityService.GetClientIp();
|
||||
user.LoginCount++;
|
||||
|
||||
//((PersistingRevalidatingAuthenticationStateProvider) _authenticationStateProvider).
|
||||
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
|
||||
return new JsonResult(loginResult);
|
||||
|
||||
|
||||
@@ -55,11 +55,11 @@ namespace Atomx.Admin.Services
|
||||
/// <returns></returns>
|
||||
public long GetUserId()
|
||||
{
|
||||
var userIdClaim = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimKeys.Id);
|
||||
return userIdClaim != null ? long.Parse(userIdClaim.Value) : 0;
|
||||
//var userIdClaim = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimKeys.Id);
|
||||
//return userIdClaim != null ? long.Parse(userIdClaim.Value) : 0;
|
||||
|
||||
//var id = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == ClaimKeys.Id)?.Value ?? "0";
|
||||
//return id.ToLong();
|
||||
var id = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == ClaimKeys.Id)?.Value ?? "0";
|
||||
return id.ToLong();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,11 +68,11 @@ namespace Atomx.Admin.Services
|
||||
/// <returns></returns>
|
||||
public int GetUserRoleId()
|
||||
{
|
||||
var userIdClaim = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimKeys.Role);
|
||||
return userIdClaim != null ? int.Parse(userIdClaim.Value) : 0;
|
||||
//var userIdClaim = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimKeys.Role);
|
||||
//return userIdClaim != null ? int.Parse(userIdClaim.Value) : 0;
|
||||
|
||||
//var id = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == ClaimTypes.Sid)?.Value ?? "0";
|
||||
//return id.ToLong();
|
||||
var id = _httpContextAccessor.HttpContext?.User?.Claims?.SingleOrDefault(p => p.Type == ClaimKeys.Role)?.Value ?? "0";
|
||||
return id.ToInt();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user