Add LastLogin and CreatedAt to User

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-09-21 23:57:37 +03:00
parent 1fcaba383e
commit 0af74ec278
7 changed files with 49 additions and 3 deletions
+13 -1
View File
@@ -34,7 +34,8 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
Id = Guid.NewGuid(),
Email = request.Email,
PasswordHash = request.Password.ToHash(),
Role = request.Role
Role = request.Role,
CreatedAt = DateTime.UtcNow
}, token: ct);
});
}
@@ -108,12 +109,23 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
{
await UpdateHardware(user.Email, hardware, ct);
cache.Invalidate(User.GetCacheKey(user.Email));
await UpdateLastLoginDate(user, ct);
return requestHWHash;
}
var userHWHash = Security.GetHWHash(user.Hardware);
if (userHWHash != requestHWHash)
throw new BusinessException(ExceptionEnum.HardwareIdMismatch);
await UpdateLastLoginDate(user, ct);
return userHWHash;
}
private async Task UpdateLastLoginDate(User user, CancellationToken ct = default)
{
await dbFactory.Run(async db =>
await db.Users.UpdateAsync(x => x.Email == user.Email, u => new User
{
LastLogin = DateTime.UtcNow
}, ct));
}
}