public ActionResult <OutputDtoAuthenticateUser> Authenticate([FromBody] InputDtoAuthenticateUser user) { try { var response = _userService.Authenticate(user); return(Ok(response)); } catch (NullUserException e) { return(BadRequest(new { message = e.Message })); } catch (WrongPasswordException e) { return(BadRequest(new { message = e.Message })); } }
public OutputDtoAuthenticateUser Authenticate(InputDtoAuthenticateUser user) { var userFromDb = _userRepository.Authenticate(new User { Email = user.Email }); if (userFromDb == null) { throw new NullUserException(); } bool passwordVerified = _passwordEncryption.VerifyPassword( userFromDb, userFromDb.EncryptedPassword, user.PasswordUser); if (!passwordVerified) { throw new WrongPasswordException(); } var token = GenerateJwtToken(userFromDb); return(new OutputDtoAuthenticateUser(userFromDb, token)); }