Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * @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;
 }
 /**
  * @param User $user
  * @param string $email
  *
  * @return EmailToken
  */
 protected function generateToken(User $user, $email)
 {
     $token = EmailToken::generate($email, $user->id);
     $token->save();
     return $token;
 }