public async Task <bool> AuthenticateUserAsync(AuthenticateAdminUserDto dto) { var adminUser = await _adminUserRepository.GetAdminUserByUsernameAsync(dto.Username); if (adminUser is null) { return(false); } return(Crypto.VerifyHashedPassword(adminUser.Password, dto.Password)); }
public async Task <IActionResult> AuthenticateUser([FromBody] AuthenticateAdminUserDto dto) { var isAuthenticated = await _adminUserService.AuthenticateUserAsync(dto); if (!isAuthenticated) { return(new JsonResult(new ErrorDto("Invalid credentials")) { StatusCode = StatusCodes.Status401Unauthorized }); } var token = _tokenService.GenerateAdminToken(dto.Username); return(new JsonResult(new TokenDto(token))); }