/** * @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; }