mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-30 10:33:43 +00:00
Seal classes
This commit is contained in:
parent
d6eb9d10f3
commit
39c720607f
@ -14,7 +14,7 @@ namespace CleanArchitecture.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/v1/[controller]")]
|
||||
public class UserController : ApiController
|
||||
public sealed class UserController : ApiController
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
|
||||
|
@ -71,7 +71,7 @@ public sealed class ApiUser : IUser
|
||||
return identity.Name;
|
||||
}
|
||||
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;
|
||||
_name = claim ?? string.Empty;
|
||||
return _name;
|
||||
|
@ -4,7 +4,7 @@ using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CleanArchitecture.Domain.Enums;
|
||||
using CleanArchitecture.Domain.Entities;
|
||||
using CleanArchitecture.Domain.Errors;
|
||||
using CleanArchitecture.Domain.Interfaces;
|
||||
using CleanArchitecture.Domain.Interfaces.Repositories;
|
||||
@ -70,19 +70,18 @@ public sealed class LoginUserCommandHandler : CommandHandlerBase,
|
||||
}
|
||||
|
||||
return BuildToken(
|
||||
user.Email,
|
||||
user.Role,
|
||||
user.Id,
|
||||
user,
|
||||
_tokenSettings);
|
||||
}
|
||||
|
||||
private static string BuildToken(string email, UserRole role, Guid id, TokenSettings tokenSettings)
|
||||
private static string BuildToken(User user, TokenSettings tokenSettings)
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.Email, email),
|
||||
new Claim(ClaimTypes.Role, role.ToString()),
|
||||
new Claim(ClaimTypes.NameIdentifier, id.ToString())
|
||||
new Claim(ClaimTypes.Email, user.Email),
|
||||
new Claim(ClaimTypes.Role, user.Role.ToString()),
|
||||
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||
new Claim(ClaimTypes.Name, user.FullName)
|
||||
};
|
||||
|
||||
var securityKey = new SymmetricSecurityKey(
|
||||
|
@ -4,7 +4,7 @@ using FluentValidation;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -14,7 +14,7 @@ public static class CustomValidator
|
||||
private static bool IsBase64String(string base64)
|
||||
{
|
||||
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>(
|
||||
@ -32,4 +32,7 @@ public static class CustomValidator
|
||||
.Matches("[^a-zA-Z0-9]").WithErrorCode(DomainErrorCodes.UserSpecialCharPassword);
|
||||
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;
|
||||
|
||||
public class DomainEventStore : IDomainEventStore
|
||||
public sealed class DomainEventStore : IDomainEventStore
|
||||
{
|
||||
private readonly EventStoreDbContext _eventStoreDbContext;
|
||||
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
||||
|
Loading…
Reference in New Issue
Block a user