/**
  * Look up an email address to see if it can be used to create a new account.
  * @param LookupEmailRequest $request
  * @return $this
  */
 public function lookupEmail(LookupEmailRequest $request)
 {
     if ($this->getThrottleValue("email_lookup", md5($request->getClientIp())) > 10) {
         return redirect()->back()->withErrors(trans("errors.tooManyFailedLookupAttempts"));
     }
     $accountAuthenticationController = new AccountAuthenticationController();
     try {
         $result = $accountAuthenticationController->lookupEmail($request->input('email'));
     } catch (Exception $e) {
         $this->incrementThrottleValue("email_lookup", md5($request->getClientIp()));
         return redirect()->back()->withErrors(trans("errors.emailLookupFailed"));
     }
     $creationToken = CreationToken::where('account_id', '=', $result->account_id)->where('contact_id', '=', $result->contact_id)->first();
     if ($creationToken === null) {
         $creationToken = new CreationToken(['token' => uniqid(), 'email' => strtolower($result->email_address), 'account_id' => $result->account_id, 'contact_id' => $result->contact_id]);
     } else {
         $creationToken->token = uniqid();
     }
     $creationToken->save();
     try {
         Mail::send('emails.account_create', ['portal_url' => Config::get("app.url"), 'creation_link' => Config::get("app.url") . "/create/" . $creationToken->token], 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)->subject(trans("emails.createAccount", ['companyName' => Config::get("customer_portal.company_name")]));
         });
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return redirect()->back()->withErrors(trans("errors.emailSendFailed"));
     }
     $this->resetThrottleValue("email_lookup", md5($request->getClientIp()));
     return redirect()->action("AuthenticationController@index")->with('success', trans("root.emailFound"));
 }