public IActionResult SignIn(SignIn signIn) { // (1) Get User by his Credentials [userId - userPassword] // and validate the userPassword against Passwordhash user = _service.GetOne <User>(u => u.Email == signIn.Email && UserHelpers.ValidateHash(signIn.Password, u.PasswordSalt, u.PasswordHash)); // (2) if User doesn't exist return badRequest if (user == null) { return(BadRequest(new Error() { Message = "Invalid User." })); } // (3) if User is [isDeleted] return badRequest if (user.IsDeleted == true) { return(BadRequest(new Error() { Message = "Invalid User." })); } // (4) Map the Entity User to View User [VUser] vUser = _mapper.Map <UserView>(user); // (5) if everything is ok, return the [vUser - accessToken] return(Ok(new { User = vUser, AccessToken = UserHelpers.GetToken(vUser) } )); }
public IActionResult ChangePassword([FromBody] ChangedPassword changedpassword) { // (1) Get User by his Credentials [UserId - OldPassword] var user = _service.GetOne <User>(u => u.Email == changedpassword.Email && UserHelpers.ValidateHash(changedpassword.OldPassword, u.PasswordSalt, u.PasswordHash)); // (2) if user not found then return [BadRequest] if (user == null) { return(BadRequest(new Error() { Message = "Invalid User." })); } return(_DoChangePassword(user, changedpassword.NewPassword)); }