Add settings endpoints and registration status check: implement new API endpoints for settings management, including registration status retrieval, and update the registration command handler to enforce registration rules based on site settings.
This commit is contained in:
@@ -26,4 +26,9 @@ public static class AuthErrors
|
||||
"Auth.UserNameTaken",
|
||||
"Это имя пользователя уже занято."
|
||||
);
|
||||
|
||||
public static readonly Error RegistrationDisabled = Error.Forbidden(
|
||||
"Auth.RegistrationDisabled",
|
||||
"Регистрация на сайте отключена администратором."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace TeleWave.Application.Auth.Register;
|
||||
public sealed class RegisterCommandHandler(
|
||||
IIdentityService identityService,
|
||||
IJwtTokenService jwtTokenService,
|
||||
IRefreshTokenService refreshTokenService
|
||||
IRefreshTokenService refreshTokenService,
|
||||
ISiteSettings siteSettings
|
||||
) : ICommandHandler<RegisterCommand, Result<AuthResult>>
|
||||
{
|
||||
public async Task<Result<AuthResult>> Handle(
|
||||
@@ -15,6 +16,10 @@ public sealed class RegisterCommandHandler(
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
// Открытая регистрация должна быть явно включена админом; иначе учётки заводит только он.
|
||||
if (!await siteSettings.IsRegistrationEnabledAsync(cancellationToken))
|
||||
return Result.Failure<AuthResult>(AuthErrors.RegistrationDisabled);
|
||||
|
||||
var createResult = await identityService.CreateUserAsync(
|
||||
command.UserName,
|
||||
command.Password,
|
||||
|
||||
Reference in New Issue
Block a user