feat(backend): add add email address endpoint

This commit is contained in:
sam 2024-10-02 00:52:49 +02:00
parent 7f971e8549
commit 5b17c716cb
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 114 additions and 3 deletions

View file

@ -129,6 +129,30 @@ public class AuthService(IClock clock, DatabaseContext db, ISnowflakeGenerator s
return (user, EmailAuthenticationResult.AuthSuccessful);
}
/// <summary>
/// Validates a user's password outside an authentication context, for when a password is required for changing
/// a setting, such as adding a new email address or changing passwords.
/// </summary>
public async Task<bool> ValidatePasswordAsync(
User user,
string password,
CancellationToken ct = default
)
{
if (user.Password == null)
{
throw new FoxnounsError("Password for user supplied to ValidatePasswordAsync was null");
}
var pwResult = await Task.Run(
() => _passwordHasher.VerifyHashedPassword(user, user.Password!, password),
ct
);
return pwResult
is PasswordVerificationResult.SuccessRehashNeeded
or PasswordVerificationResult.Success;
}
public enum EmailAuthenticationResult
{
AuthSuccessful,