mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 18:09:04 +00:00
Create ConfirmationService class file and extract out of interface file
This commit is contained in:
34
src/Core/Service/Service.Auth/ConfirmationService.cs
Normal file
34
src/Core/Service/Service.Auth/ConfirmationService.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
using Domain.Exceptions;
|
||||||
|
using Infrastructure.Repository.Auth;
|
||||||
|
|
||||||
|
namespace Service.Auth;
|
||||||
|
|
||||||
|
public class ConfirmationService(
|
||||||
|
IAuthRepository authRepository,
|
||||||
|
ITokenService tokenService
|
||||||
|
) : IConfirmationService
|
||||||
|
{
|
||||||
|
public async Task<ConfirmationServiceReturn> ConfirmUserAsync(
|
||||||
|
string confirmationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var validatedToken = await tokenService.ValidateConfirmationTokenAsync(
|
||||||
|
confirmationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
var user = await authRepository.ConfirmUserAccountAsync(
|
||||||
|
validatedToken.UserId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new UnauthorizedException("User account not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ConfirmationServiceReturn(
|
||||||
|
DateTime.UtcNow,
|
||||||
|
user.UserAccountId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,27 +9,3 @@ public interface IConfirmationService
|
|||||||
{
|
{
|
||||||
Task<ConfirmationServiceReturn> ConfirmUserAsync(string confirmationToken);
|
Task<ConfirmationServiceReturn> ConfirmUserAsync(string confirmationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfirmationService(IAuthRepository authRepository, ITokenService tokenService)
|
|
||||||
: IConfirmationService
|
|
||||||
{
|
|
||||||
public async Task<ConfirmationServiceReturn> ConfirmUserAsync(
|
|
||||||
string confirmationToken
|
|
||||||
)
|
|
||||||
{
|
|
||||||
var validatedToken = await tokenService.ValidateConfirmationTokenAsync(
|
|
||||||
confirmationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
var user = await authRepository.ConfirmUserAccountAsync(
|
|
||||||
validatedToken.UserId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new UnauthorizedException("User account not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ConfirmationServiceReturn(DateTime.UtcNow, user.UserAccountId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user