mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-07-12 00:25:05 +00:00
Seal classes
This commit is contained in:
parent
d6eb9d10f3
commit
39c720607f
@ -14,7 +14,7 @@ namespace CleanArchitecture.Api.Controllers;
|
|||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/v1/[controller]")]
|
[Route("/api/v1/[controller]")]
|
||||||
public class UserController : ApiController
|
public sealed class UserController : ApiController
|
||||||
{
|
{
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public sealed class ApiUser : IUser
|
|||||||
return identity.Name;
|
return identity.Name;
|
||||||
}
|
}
|
||||||
var claim = _httpContextAccessor.HttpContext!.User.Claims
|
var claim = _httpContextAccessor.HttpContext!.User.Claims
|
||||||
.FirstOrDefault(c => string.Equals(c.Type, "name", StringComparison.OrdinalIgnoreCase))?
|
.FirstOrDefault(c => string.Equals(c.Type, ClaimTypes.Name, StringComparison.OrdinalIgnoreCase))?
|
||||||
.Value;
|
.Value;
|
||||||
_name = claim ?? string.Empty;
|
_name = claim ?? string.Empty;
|
||||||
return _name;
|
return _name;
|
||||||
|
@ -4,7 +4,7 @@ using System.Security.Claims;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CleanArchitecture.Domain.Enums;
|
using CleanArchitecture.Domain.Entities;
|
||||||
using CleanArchitecture.Domain.Errors;
|
using CleanArchitecture.Domain.Errors;
|
||||||
using CleanArchitecture.Domain.Interfaces;
|
using CleanArchitecture.Domain.Interfaces;
|
||||||
using CleanArchitecture.Domain.Interfaces.Repositories;
|
using CleanArchitecture.Domain.Interfaces.Repositories;
|
||||||
@ -70,19 +70,18 @@ public sealed class LoginUserCommandHandler : CommandHandlerBase,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return BuildToken(
|
return BuildToken(
|
||||||
user.Email,
|
user,
|
||||||
user.Role,
|
|
||||||
user.Id,
|
|
||||||
_tokenSettings);
|
_tokenSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string BuildToken(string email, UserRole role, Guid id, TokenSettings tokenSettings)
|
private static string BuildToken(User user, TokenSettings tokenSettings)
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
new Claim(ClaimTypes.Email, email),
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
new Claim(ClaimTypes.Role, role.ToString()),
|
new Claim(ClaimTypes.Role, user.Role.ToString()),
|
||||||
new Claim(ClaimTypes.NameIdentifier, id.ToString())
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.FullName)
|
||||||
};
|
};
|
||||||
|
|
||||||
var securityKey = new SymmetricSecurityKey(
|
var securityKey = new SymmetricSecurityKey(
|
||||||
|
@ -4,7 +4,7 @@ using FluentValidation;
|
|||||||
|
|
||||||
namespace CleanArchitecture.Domain.Extensions.Validation;
|
namespace CleanArchitecture.Domain.Extensions.Validation;
|
||||||
|
|
||||||
public static class CustomValidator
|
public static partial class CustomValidator
|
||||||
{
|
{
|
||||||
public static IRuleBuilderOptions<T, string> StringMustBeBase64<T>(this IRuleBuilder<T, string> ruleBuilder)
|
public static IRuleBuilderOptions<T, string> StringMustBeBase64<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||||
{
|
{
|
||||||
@ -14,7 +14,7 @@ public static class CustomValidator
|
|||||||
private static bool IsBase64String(string base64)
|
private static bool IsBase64String(string base64)
|
||||||
{
|
{
|
||||||
base64 = base64.Trim();
|
base64 = base64.Trim();
|
||||||
return base64.Length % 4 == 0 && Regex.IsMatch(base64, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
|
return base64.Length % 4 == 0 && Base64Regex().IsMatch(base64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRuleBuilder<T, string> Password<T>(
|
public static IRuleBuilder<T, string> Password<T>(
|
||||||
@ -32,4 +32,7 @@ public static class CustomValidator
|
|||||||
.Matches("[^a-zA-Z0-9]").WithErrorCode(DomainErrorCodes.UserSpecialCharPassword);
|
.Matches("[^a-zA-Z0-9]").WithErrorCode(DomainErrorCodes.UserSpecialCharPassword);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex("^[a-zA-Z0-9\\+/]*={0,3}$", RegexOptions.None)]
|
||||||
|
private static partial Regex Base64Regex();
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace CleanArchitecture.Infrastructure.EventSourcing;
|
namespace CleanArchitecture.Infrastructure.EventSourcing;
|
||||||
|
|
||||||
public class DomainEventStore : IDomainEventStore
|
public sealed class DomainEventStore : IDomainEventStore
|
||||||
{
|
{
|
||||||
private readonly EventStoreDbContext _eventStoreDbContext;
|
private readonly EventStoreDbContext _eventStoreDbContext;
|
||||||
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
||||||
|
Loading…
Reference in New Issue
Block a user