/** * @param User $user * * @return UserSession * * @throws AuthenticationFailException */ public function login(User $user) : UserSession { if (!$this->userRepository->exists($user)) { throw new AuthenticationFailException('User not exists'); } $userSession = $this->userSessionRepository->getByUser($user); if (!$userSession) { $userToken = $this->userTokenFactory->create($user); /** @var UserSession $userSession */ $userSession = $this->userSessionFactory->create(); $userSession->setUser($user); $userSession->setToken($userToken); $this->userSessionRepository->save($userSession); } return $userSession; }
/** * @param User $user * @return boolean */ public function exists(User $user) : bool { return $this->userRepository->exists($user); }