/** * @param InteractiveLoginEvent $event */ public function onLogin(InteractiveLoginEvent $event) { $user = $event->getAuthenticationToken()->getUser(); if ($user instanceof LoginInfoInterface) { $user->setLastLogin(new \DateTime('now', new \DateTimeZone('UTC')))->setLoginCount($user->getLoginCount() + 1); /** @var UserInterface $user */ $this->userManager->updateUser($user); } }
/** * @param bool $withRole * * @return User */ protected function getUser($withRole = false) { $user = $this->userManager->createUser(); if ($withRole) { $role = new Role(User::ROLE_ADMINISTRATOR); $user->addRole($role); } return $user; }
/** * Finds a user by username. * This method is meant to be an extension point for possible child classes. * * @param string $username * @return UserInterface|null */ protected function findUser($username) { return $this->userManager->findUserByUsernameOrEmail($username); }