/**
  * 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"));
 }
 /**
  * Check for, and email a password reset if email is valid.
  * @param SendPasswordResetRequest $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function sendResetEmail(SendPasswordResetRequest $request)
 {
     if ($this->getThrottleValue("password_reset", md5($request->getClientIp())) > 5) {
         return redirect()->back()->withErrors(trans("errors.tooManyPasswordResetRequests"));
     }
     $accountAuthenticationController = new AccountAuthenticationController();
     try {
         $result = $accountAuthenticationController->lookupEmail($request->input('email'), false);
     } catch (Exception $e) {
         $this->incrementThrottleValue("password_reset", md5($request->getClientIp()));
         return redirect()->back()->withErrors(trans("errors.resetLookupFailed"));
     }
     $passwordReset = PasswordReset::where('account_id', '=', $result->account_id)->where('contact_id', '=', $result->contact_id)->first();
     if ($passwordReset === null) {
         $passwordReset = new PasswordReset(['token' => uniqid(), 'email' => $result->email_address, 'contact_id' => $result->contact_id, 'account_id' => $result->account_id]);
     } else {
         $passwordReset->token = uniqid();
     }
     $passwordReset->save();
     try {
         Mail::send('emails.password_reset', ['portal_url' => Config::get("app.url"), 'reset_link' => Config::get("app.url") . "/reset/" . $passwordReset->token, 'username' => $result->username], function ($m) use($result) {
             $m->from(Config::get("customer_portal.from_address"), Config::get("customer_portal.from_name"));
             $m->to($result->email_address, $result->email_address);
             $m->subject(trans("emails.passwordReset", ['companyName' => Config::get("customer_portal.company_name")]));
         });
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return redirect()->back()->withErrors(trans("errors.emailSendFailed"));
     }
     return redirect()->action("AuthenticationController@index")->with('success', trans("root.resetSent"));
 }