/
bazhinilya
/
net-simple-jwt
Обзор
Документация
Войти
/
bazhinilya
/
net-simple-jwt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
Data/UserRepository.cs
90 строк
3 KB
bazhinilya
Initial commit
16 июн 2026, 23:19
16 июн 2026, 23:19
afe56b6
Код
Авторство
О чём код?
using net_simple_jwt.Entities; namespace net_simple_jwt.Data; public class UserRepository(AuthDbContext _dbContext) : IUserRepository { public async Task<User?> GetByEmailAsync(string email) => await _dbContext.Users.AsQueryable() .FirstOrDefaultAsync(u => u.Email == email); public async Task<User?> GetByIdAsync(Guid id) => await _dbContext.Users.AsQueryable() .FirstOrDefaultAsync(u => u.Id == id); public async Task<User?> GetByRefreshTokenAsync(string refreshToken) => await _dbContext.Users.AsQueryable() .FirstOrDefaultAsync(u => u.RefreshToken == refreshToken); public async Task CreateAsync(User user) { await _dbContext.Users.InsertAsync(user); await _dbContext.SaveChangesAsync(); } public async Task UpdateAsync(User user) { await _dbContext.SaveChangesAsync(); } public async Task UpdateRefreshTokenAsync(Guid userId, string? refreshToken, DateTime? expiryTime) { var user = await GetByIdAsync(userId); if (user != null) { user.RefreshToken = refreshToken; user.RefreshTokenExpiryTime = expiryTime; user.UpdatedAt = DateTime.UtcNow; await _dbContext.SaveChangesAsync(); } } public async Task RemoveRefreshTokenAsync(string refreshToken) { var user = await GetByRefreshTokenAsync(refreshToken); if (user != null) { user.RefreshToken = null; user.RefreshTokenExpiryTime = null; await _dbContext.SaveChangesAsync(); } } public async Task IncrementFailedAttemptsAsync(Guid userId) { var user = await GetByIdAsync(userId); if (user != null) { user.FailedLoginAttempts++; user.UpdatedAt = DateTime.UtcNow; await _dbContext.SaveChangesAsync(); } } public async Task ResetFailedAttemptsAsync(Guid userId) { var user = await GetByIdAsync(userId); if (user != null) { user.FailedLoginAttempts = 0; user.LockoutEnd = null; await _dbContext.SaveChangesAsync(); } } public async Task LockoutAsync(Guid userId, DateTime lockoutEnd) { var user = await GetByIdAsync(userId); if (user != null) { user.LockoutEnd = lockoutEnd; await _dbContext.SaveChangesAsync(); } } public async Task DeleteAsync(Guid userId) { if (userId != Guid.Empty) { await _dbContext.Users.DeleteAsync(userId); await _dbContext.SaveChangesAsync(); } } }