46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Project.Domain.Entities;
|
|
using Project.Infrastructure.Interfaces;
|
|
|
|
namespace Project.Infrastructure.Repositories
|
|
{
|
|
public class TwoFactorAuthRepository : ITwoFactorAuthRepository
|
|
{
|
|
// FIELDS FOR CTOR
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
// CTOR
|
|
public TwoFactorAuthRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// GET USER BY EMAIL
|
|
public async Task<User> GetUserByEmailAsync(string email)
|
|
{
|
|
return await _context.Users.FirstAsync(user => user.Email == email);
|
|
}
|
|
|
|
// GET SECRET KEY
|
|
public async Task<string> GetSecretKeyAsync(string email)
|
|
{
|
|
return await _context.Users
|
|
.Where(user => user.Email == email)
|
|
.Select(user => user.SecretKey)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
// SAVE SECRET KEY
|
|
public async Task<bool> SaveSecretKeyAsync(string email, string secretKey)
|
|
{
|
|
User user = await _context.Users.FirstAsync(user => user.Email == email);
|
|
|
|
user.SecretKey = secretKey;
|
|
|
|
_context.Entry(user).State = EntityState.Modified;
|
|
var results = await _context.SaveChangesAsync();
|
|
return results > 0;
|
|
}
|
|
}
|
|
}
|