コード例 #1
0
 /**
  * @param ConfirmEmail $command
  *
  * @throws InvalidConfirmationTokenException
  *
  * @return \Flarum\Core\Users\User
  */
 public function handle(ConfirmEmail $command)
 {
     $token = EmailToken::validOrFail($command->token);
     $user = $token->user;
     $user->changeEmail($token->email);
     if (!$user->is_activated) {
         $user->activate();
     }
     $user->save();
     $this->dispatchEventsFor($user);
     $token->delete();
     return $user;
 }
コード例 #2
0
ファイル: ConfirmEmailHandler.php プロジェクト: huytd/core
 /**
  * @param ConfirmEmail $command
  * @return \Flarum\Core\Users\User
  * @throws InvalidConfirmationTokenException
  */
 public function handle(ConfirmEmail $command)
 {
     $token = EmailToken::find($command->token);
     if (!$token || $token->created_at < new DateTime('-1 day')) {
         throw new InvalidConfirmationTokenException();
     }
     $user = $token->user;
     $user->changeEmail($token->email);
     if (!$user->is_activated) {
         $user->activate();
     }
     $user->save();
     $this->dispatchEventsFor($user);
     $token->delete();
     return $user;
 }
コード例 #3
0
 /**
  * @param User $user
  * @param string $email
  *
  * @return EmailToken
  */
 protected function generateToken(User $user, $email)
 {
     $token = EmailToken::generate($email, $user->id);
     $token->save();
     return $token;
 }