* Added Authentication
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user