mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
remove email out of register service
This commit is contained in:
@@ -9,12 +9,10 @@ namespace Service.Auth;
|
|||||||
|
|
||||||
public class RegisterService(
|
public class RegisterService(
|
||||||
IAuthRepository authRepo,
|
IAuthRepository authRepo,
|
||||||
IPasswordInfrastructure passwordInfrastructure,
|
IPasswordInfrastructure passwordInfrastructure
|
||||||
IEmailProvider emailProvider,
|
|
||||||
IEmailTemplateProvider emailTemplateProvider
|
|
||||||
) : IRegisterService
|
) : IRegisterService
|
||||||
{
|
{
|
||||||
public async Task<UserAccount> RegisterAsync(UserAccount userAccount, string password)
|
private async Task ValidateUserDoesNotExist(UserAccount userAccount)
|
||||||
{
|
{
|
||||||
// Check if user already exists
|
// Check if user already exists
|
||||||
var existingUsername = await authRepo.GetUserByUsernameAsync(userAccount.Username);
|
var existingUsername = await authRepo.GetUserByUsernameAsync(userAccount.Username);
|
||||||
@@ -24,8 +22,11 @@ public class RegisterService(
|
|||||||
{
|
{
|
||||||
throw new ConflictException("Username or email already exists");
|
throw new ConflictException("Username or email already exists");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserAccount> RegisterAsync(UserAccount userAccount, string password)
|
||||||
|
{
|
||||||
|
await ValidateUserDoesNotExist(userAccount);
|
||||||
// password hashing
|
// password hashing
|
||||||
var hashed = passwordInfrastructure.Hash(password);
|
var hashed = passwordInfrastructure.Hash(password);
|
||||||
|
|
||||||
@@ -38,24 +39,6 @@ public class RegisterService(
|
|||||||
userAccount.DateOfBirth,
|
userAccount.DateOfBirth,
|
||||||
hashed);
|
hashed);
|
||||||
|
|
||||||
|
|
||||||
// Generate confirmation link (TODO: implement proper token-based confirmation)
|
|
||||||
var confirmationLink = $"https://thebiergarten.app/confirm?email={Uri.EscapeDataString(createdUser.Email)}";
|
|
||||||
|
|
||||||
// Render email template
|
|
||||||
var emailHtml = await emailTemplateProvider.RenderUserRegisteredEmailAsync(
|
|
||||||
createdUser.FirstName,
|
|
||||||
confirmationLink
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send welcome email with rendered template
|
|
||||||
await emailProvider.SendAsync(
|
|
||||||
createdUser.Email,
|
|
||||||
"Welcome to The Biergarten App!",
|
|
||||||
emailHtml,
|
|
||||||
isHtml: true
|
|
||||||
);
|
|
||||||
|
|
||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user