Skip to content

Commit

Permalink
Reset password reset key functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Apr 24, 2024
1 parent a5c5933 commit 3b59800
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public interface IUserRepository : IAsyncRepository<User, Guid>
/// <param name="id">Entity identifier.</param>
Task ResetAccessFailed(Guid id);

/// <summary>
/// Reset password reset key.
/// </summary>
/// <param name="id">Entity identifier.</param>
Task ResetResetKey(Guid id);

/// <summary>
/// Register a new user login.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/FunderMaps.Core/Services/SignInService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public async Task ResetNewPasswordAsync(string email, Guid resetKey, string newP
var user = await userRepository.GetByResetKeyAsync(email.Trim().ToLowerInvariant(), resetKey);
await SetPasswordAsync(user.Id, newPassword.Trim());

// TODO: Clear ALL reset keys for user.
await userRepository.ResetAccessFailed(user.Id);
await userRepository.ResetResetKey(user.Id);
}
catch (EntityNotFoundException)
{
Expand Down
15 changes: 13 additions & 2 deletions src/FunderMaps.Data/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ UPDATE application.user
await connection.ExecuteAsync(sql, new { id });
}

// TODO: Move reset key to separate method.
/// <summary>
/// Reset signin failure count.
/// </summary>
Expand All @@ -389,8 +388,20 @@ public async Task ResetAccessFailed(Guid id)
var sql = @"
UPDATE application.user
SET access_failed_count = 0
WHERE id = @id;
WHERE id = @id";

await using var connection = DbContextFactory.DbProvider.ConnectionScope();

await connection.ExecuteAsync(sql, new { id });
}

/// <summary>
/// Reset password reset key.
/// </summary>
/// <param name="id">Entity identifier.</param>
public async Task ResetResetKey(Guid id)
{
var sql = @"
DELETE FROM application.reset_key
WHERE user_id = @id";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ public async Task ResetAccessFailed(Guid id)
memory[id].AccessFailedCount = 0;
}

public async Task ResetResetKey(Guid id)
{
await Task.CompletedTask;

throw new NotImplementedException();
}

public async Task RegisterAccess(Guid id)
{
await Task.CompletedTask;
Expand Down

0 comments on commit 3b59800

Please sign in to comment.