/** * Execute the console command. * * @return mixed */ public function handle() { $deleteTokensOlderThan = Carbon::now("UTC")->subHours(24)->toDateTimeString(); CreationToken::where('updated_at', '<=', $deleteTokensOlderThan)->delete(); PasswordReset::where('updated_at', '<=', $deleteTokensOlderThan)->delete(); $this->info("Tokens deleted."); }
/** * Create a new account * @param AccountCreationRequest $request * @param $token * @return $this */ public function createAccount(AccountCreationRequest $request, $token) { if ($this->getThrottleValue("create_account", md5($token . $request->getClientIp())) > 10) { return redirect()->back()->withErrors(trans("errors.tooManyFailedCreationAttempts")); } $creationToken = CreationToken::where('token', '=', trim($token))->where('updated_at', '>=', Carbon::now("UTC")->subHours(24)->toDateTimeString())->first(); if ($creationToken === null) { $this->incrementThrottleValue("email_lookup", md5($token . $request->getClientIp())); return redirect()->action("AuthenticationController@showRegistrationForm")->withErrors(trans("errors.invalidToken")); } if (strtolower(trim($creationToken->email)) != strtolower(trim($request->input('email')))) { $this->incrementThrottleValue("email_lookup", md5($token . $request->getClientIp())); return redirect()->back()->withErrors(trans("errors.invalidEmailAddress"))->withInput(); } $accountAuthenticationController = new AccountAuthenticationController(); try { $accountAuthenticationController->createUser($creationToken->account_id, $creationToken->contact_id, $request->input('username'), $request->input('password')); } catch (Exception $e) { return redirect()->back()->withErrors($e->getMessage())->withInput(); } $creationToken->delete(); $this->resetThrottleValue("email_lookup", md5($token . $request->getClientIp())); return redirect()->action("AuthenticationController@index")->with('success', trans("register.accountCreated")); }