internal CustomerDTO Login(UserDTO user) { bool usernameExists = _accountContract.CheckIfUsernameExist(user.Username); if (!usernameExists) { throw new Exception($"Username {user.Username} does not exist"); } CustomerDTO dto = _accountContract.GetCustomerByUsername(user.Username, true); string hashedPwd = GetHashedPassword(user.Password); if (hashedPwd != dto.Password) { throw new Exception("Invlid password"); } dto.Password = null; return(dto); }
public IActionResult IsUsernameTaken([FromBody] UsernameDTO username) { if (username == null) { return(BadRequest("There was a problem with the validation of the request parameters for verify existing username")); } try { bool exist = _contract.CheckIfUsernameExist(username.Username); return(Ok(exist)); } catch (ValidationException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(InternalServerError(ex.Message)); } }