Základní backend: migrace, autentizace JWT, role, Swagger
- Helpdesk.Migrator (DbUp) aplikuje db/migrations, evidence v schema_version - Domain/Application/Infrastructure/Api podle Clean Architecture - registrace, ověření e-mailu, login, refresh s rotací, logout, reset hesla - JWT podle RFC 7519 evidované jen podle jti v auth_token - správa uživatelů a rolí, číselníky, ProblemDetails, Swagger UI - Docker Compose (db, migrator, api), oddělené DB účty - notifikace mají cizí klíče na issue a proposal - unit testy domény a zabezpečení Closes #1, closes #2, closes #3, closes #4, closes #5, closes #9
This commit is contained in:
1 parent
fc76be7d69
commit
a51d386278
64 files changed
+4394
-1
No files matched your search
@@ -0,0 +1,63 @@
|
||||
using FluentValidation;
|
||||
using Helpdesk.Application.Users;
|
||||
|
||||
namespace Helpdesk.Application.Auth;
|
||||
|
||||
public sealed record RegisterRequest(string Email, string Password, string FirstName, string LastName);
|
||||
|
||||
public sealed record LoginRequest(string Email, string Password);
|
||||
|
||||
/// <summary>Refresh token – pro <c>/auth/refresh</c> i <c>/auth/logout</c>.</summary>
|
||||
public sealed record RefreshTokenRequest(string RefreshToken);
|
||||
|
||||
/// <summary>Token z odkazu v e-mailu (ověření e-mailu).</summary>
|
||||
public sealed record EmailTokenRequest(string Token);
|
||||
|
||||
public sealed record ForgotPasswordRequest(string Email);
|
||||
|
||||
public sealed record ResetPasswordRequest(string Token, string NewPassword);
|
||||
|
||||
public sealed record AuthResponse(
|
||||
string AccessToken,
|
||||
DateTime AccessTokenExpiresAt,
|
||||
string RefreshToken,
|
||||
DateTime RefreshTokenExpiresAt,
|
||||
UserDto User);
|
||||
|
||||
internal static class PasswordRules
|
||||
{
|
||||
public const int MinLength = 8;
|
||||
public const int MaxLength = 64; // BCrypt zpracuje nejvýše 72 bajtů
|
||||
|
||||
public static IRuleBuilderOptions<T, string> ValidPassword<T>(this IRuleBuilder<T, string> rule) =>
|
||||
rule.NotEmpty().MinimumLength(MinLength).MaximumLength(MaxLength);
|
||||
}
|
||||
|
||||
public sealed class RegisterRequestValidator : AbstractValidator<RegisterRequest>
|
||||
{
|
||||
public RegisterRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Email).NotEmpty().EmailAddress().MaximumLength(254);
|
||||
RuleFor(x => x.Password).ValidPassword();
|
||||
RuleFor(x => x.FirstName).NotEmpty().MaximumLength(100);
|
||||
RuleFor(x => x.LastName).NotEmpty().MaximumLength(100);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LoginRequestValidator : AbstractValidator<LoginRequest>
|
||||
{
|
||||
public LoginRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Email).NotEmpty();
|
||||
RuleFor(x => x.Password).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ResetPasswordRequestValidator : AbstractValidator<ResetPasswordRequest>
|
||||
{
|
||||
public ResetPasswordRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Token).NotEmpty();
|
||||
RuleFor(x => x.NewPassword).ValidPassword();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user