* Added Authentication

This commit is contained in:
2025-02-21 09:59:50 +01:00
parent ed5b5634fd
commit 6774311433
20 changed files with 468 additions and 30 deletions

View File

@@ -9,6 +9,7 @@ public interface IUserService
Task<UserDto?> GetByUsername(string username);
Task<int> Add(UserDto userDto);
Task<int> Update(UserDto userDto);
Task<int> Login(UserDto userDto);
Task<int> Delete(Guid id);
Task<IList<UserRoleDto>> GetUserRoles(Guid userId);
Task<UserDto?> GetUserByLoginAndPassword(string login, string password);

View File

@@ -56,6 +56,20 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
context.Users.Update(user);
return await context.SaveChangesAsync();
}
public async Task<int> Login(UserDto userDto)
{
User? user = context.Users.FirstOrDefault(x => x.Id == userDto.Id);
if (user is null) return 0;
user.LastLoginDate = DateTime.Now;
user.FailedLoginAttempts = 0;
context.Users.Update(user);
return await context.SaveChangesAsync();
}
public async Task<int> Delete(Guid id)
{