/** * Handle a verify email request for the application. * * @param string $token * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function verifyEmail($token) { if (!($account = Verify::verifyToken($token)) instanceof Account) { return view('errors.emailVerifyFailed', ['message' => $account]); } $account->attachRole(Role::where('name', '=', 'verified-user')->first()); Event::_create('events.account', $account, 'account.verifyEmail'); return redirect()->route('home'); }
protected function make() { $this->expireOldTokens($this->category, $this->account->getAttribute('id')); $verify = Verify::create(['token' => str_random(100), 'category_id' => $this->category, 'account_id' => $this->account->getAttribute('id'), 'created_at' => Carbon::now()]); $this->data = ['token' => $verify->getAttribute('token')]; }
/** * Expire old verify tokens. * * @param int $categoryId * @param int $accountId * @return bool|null */ protected function expireOldTokens($categoryId, $accountId) { return Verify::where('category_id', '=', $categoryId)->where('account_id', '=', $accountId)->delete(); }