/**
  * Attempt to reset the password to a new value
  * @param PasswordUpdateRequest $request
  * @param $token
  * @return $this
  */
 public function updateContactWithNewPassword(PasswordUpdateRequest $request, $token)
 {
     if ($this->getThrottleValue("password_update", md5($request->getClientIp())) > 5) {
         return redirect()->back()->withErrors(trans("errors.tooManyFailedPasswordResets"));
     }
     $passwordReset = PasswordReset::where('token', '=', trim($token))->where('updated_at', '>=', Carbon::now("UTC")->subHours(24)->toDateTimeString())->first();
     if ($passwordReset === null) {
         $this->incrementThrottleValue("password_update", md5($token . $request->getClientIp()));
         return redirect()->action("AuthenticationController@showResetPasswordForm")->withErrors(trans("errors.invalidToken"));
     }
     if ($passwordReset->email != $request->input('email')) {
         $this->incrementThrottleValue("password_update", md5($token . $request->getClientIp()));
         return redirect()->back()->withErrors(trans("errors.invalidEmailAddress"));
     }
     $contactController = new ContactController();
     try {
         $contact = $contactController->getContact($passwordReset->contact_id, $passwordReset->account_id);
     } catch (Exception $e) {
         return redirect()->back()->withErrors(trans("errors.couldNotFindAccount"));
     }
     try {
         $contactController->updateContactPassword($contact, $request->input('password'));
     } catch (Exception $e) {
         return redirect()->back()->withErrors(trans("errors.failedToResetPassword"));
     }
     $passwordReset->delete();
     $this->resetThrottleValue("password_update", md5($token . $request->getClientIp()));
     return redirect()->action("AuthenticationController@index")->with('success', trans("register.passwordReset"));
 }
 /**
  * Update the user password
  * @param UpdatePasswordRequest $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function updatePassword(UpdatePasswordRequest $request)
 {
     //Validate that the current password is correct before allowing an update
     $accountAuthenticationController = new AccountAuthenticationController();
     try {
         $accountAuthenticationController->authenticateUser(get_user()->username, $request->input('current_password'));
     } catch (Exception $e) {
         return redirect()->back()->withErrors(trans("errors.currentPasswordInvalid"));
     }
     $contact = $this->getContact();
     $contactController = new ContactController();
     try {
         $contactController->updateContactPassword($contact, $request->input('new_password'));
     } catch (Exception $e) {
         return redirect()->back()->withErrors($e->getMessage());
     }
     return redirect()->action("ProfileController@show")->with('success', trans("profile.passwordUpdated"));
 }