/** * Attempt to activate an account * * @param string $confirmation_code * @return void */ public function activateAccount($confirmation_code) { if (!$confirmation_code) { return redirect()->to('/'); } $confirmation = AccountConfirmation::where('code', '=', $confirmation_code)->first(); if ($confirmation == null) { Flash::error('Invalid confirmation code.'); return redirect()->to('/'); } $user = $confirmation->user; if ($user == null) { Flash::error('The user associated with this confirmation code either does not exist or has been deleted.'); return redirect()->to('/'); } if ($confirmation->hasExpired()) { Flash::error('That confirmation code has expired.'); return redirect()->to('/'); } if ($user->isConfirmed()) { Flash::error('The user associated with this confirmation code has already confirmed their account.'); return redirect()->to('/'); } $user->confirmed = 1; if ($user->save()) { Flash::success('Your account has been activated. You now have access to all the features that confirmed members get.'); $confirmation->delete(); return redirect()->to('/'); } else { Flash::error('Your account could not be activated.'); return redirect()->to('/'); } }
/** * Get the user's account confirmation object. * * @return AccountConfirmation */ public function getAccountConfirmation() { $confirmation = AccountConfirmation::where('user_id', '=', $this->id)->first(); if ($confirmation == null) { return null; } if ($this->isConfirmed()) { return null; } return $confirmation; }