public function changePassword($data)
{
try {
$user = $this->sentry->getUserProvider()->findById($data['id']);
// Does the old password input match the user's existing password?
if ($user->checkHash(e($data['oldPassword']), $user->getPassword())) {
// Set the new password (Sentry will hash it behind the scenes)
$user->password = e($data['newPassword']);
if ($user->save()) {
// User saved
$this->dispatcher->fire('sentinel.user.passwordchange', ['user' => $user]);
return new SuccessResponse(trans('Sentinel::users.passwordchg'), ['user' => $user]);
}
// User not Saved
return new FailureResponse(trans('Sentinel::users.passwordprob'), ['user' => $user]);
}
// Password mismatch. Abort.
return new FailureResponse(trans('Sentinel::users.oldpassword'), ['user' => $user]);
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');
return new ExceptionResponse($message);
}
}