fix: confirm email changes and enforce clean backend build
Some checks failed
deploy-socialize / deploy (push) Has been cancelled
deploy-socialize / image (push) Has been cancelled

This commit is contained in:
2026-05-07 14:39:22 -04:00
parent 9022fa7d93
commit 57abe57bc7
54 changed files with 974 additions and 206 deletions

View File

@@ -16,13 +16,7 @@ internal sealed class AccessTokenFactory(
IList<string> roles = await userManager.GetRolesAsync(user);
IList<Claim> claims = await userManager.GetClaimsAsync(user);
string persona = roles.Contains(KnownRoles.Manager, StringComparer.Ordinal)
? KnownRoles.Manager
: roles.Contains(KnownRoles.Client, StringComparer.Ordinal)
? KnownRoles.Client
: roles.Contains(KnownRoles.Provider, StringComparer.Ordinal)
? KnownRoles.Provider
: KnownRoles.WorkspaceMember;
string persona = GetPersona(roles);
List<Claim> tokenClaims = [.. claims, new Claim(KnownClaims.Persona, persona)];
@@ -40,4 +34,24 @@ internal sealed class AccessTokenFactory(
roles,
tokenClaims);
}
private static string GetPersona(IList<string> roles)
{
if (roles.Contains(KnownRoles.Manager, StringComparer.Ordinal))
{
return KnownRoles.Manager;
}
if (roles.Contains(KnownRoles.Client, StringComparer.Ordinal))
{
return KnownRoles.Client;
}
if (roles.Contains(KnownRoles.Provider, StringComparer.Ordinal))
{
return KnownRoles.Provider;
}
return KnownRoles.WorkspaceMember;
}
}

View File

@@ -58,4 +58,52 @@ internal sealed class EmailVerificationService(
</div>
""");
}
public async Task SendEmailChangeConfirmationAsync(
User user,
string newEmail)
{
string token = await userManager.GenerateChangeEmailTokenAsync(user, newEmail);
string encodedEmail = HttpUtility.UrlEncode(newEmail);
string encodedToken = HttpUtility.UrlEncode(token);
string confirmationLink =
$"{options.Value.FrontendBaseUrl}/verify-email?changeEmail=true&userId={user.Id}&email={encodedEmail}&token={encodedToken}";
await emailSender.SendEmailAsync(
newEmail,
"Confirm your new email address",
$"""
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; color: #333;">
<h1 style="color: #2c3e50; margin-bottom: 20px;">Confirm your new email address</h1>
<p style="font-size: 16px; line-height: 1.5; margin-bottom: 25px;">
Please confirm this email address for your Socialize account by clicking the button below:
</p>
<div style="text-align: center; margin: 30px 0;">
<a href='{confirmationLink}'
style="background-color: #3498db;
color: white;
text-decoration: none;
padding: 12px 24px;
border-radius: 4px;
font-weight: bold;
display: inline-block;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
Confirm Email Address
</a>
</div>
<p style="font-size: 14px; color: #7f8c8d; margin-top: 30px;">
If you did not request this change, please ignore this email.
</p>
<p style="font-size: 14px; color: #7f8c8d; margin-top: 20px;">
If the button doesn't work, you can copy and paste this link into your browser:
<br>
<a href='{confirmationLink}' style="color: #3498db; word-break: break-all;">{confirmationLink}</a>
</p>
</div>
""");
}
}