feat(backend): add add email address endpoint
This commit is contained in:
parent
7f971e8549
commit
5b17c716cb
6 changed files with 114 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue