This commit is contained in:
Dhananjaya99
2026-07-08 11:11:50 +05:30
parent 2cd2741f77
commit de7b40a147
51 changed files with 6839 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
using AuthHex.Models;
using AuthHex.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace AuthHex.Repos
{
public class RecoveryManagerRepository : IRecoveryManagerRepository
{
private readonly AppDBContext _dbContext;
public RecoveryManagerRepository(AppDBContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Recovery> AddRecoveryAsync(Recovery recovery, CancellationToken ct = default)
{
_dbContext.Recovery.Add(recovery);
await _dbContext.SaveChangesAsync(ct);
return recovery;
}
public async Task<Recovery?> GetRecoveryByTokenHashAsync(string tokenHash, CancellationToken ct = default)
{
return await _dbContext.Recovery
.Include(r => r.User)
.FirstOrDefaultAsync(r => r.ResetTokenHash == tokenHash && !r.IsUsed, ct);
}
public async Task<Recovery?> GetRecoveryByReferenceNumAsync(string referenceNum, CancellationToken ct = default)
{
return await _dbContext.Recovery
.Include(r => r.User)
.FirstOrDefaultAsync(r => r.RecoveryReferenceNum == referenceNum, ct);
}
public async Task UpdateRecoveryAsync(Recovery recovery, CancellationToken ct = default)
{
_dbContext.Recovery.Update(recovery);
await _dbContext.SaveChangesAsync(ct);
}
public async Task<List<Recovery>> GetPendingRecoveriesByUserIdAsync(Guid userId, CancellationToken ct = default)
{
return await _dbContext.Recovery
.Where(r => r.UserId == userId && !r.IsUsed && r.Status == "Pending")
.ToListAsync(ct);
}
}
}