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