/** * @param UsersRepository $repo * @param string $userLogin * * @return Entity\Users */ protected function getUser(UsersRepository $repo, $userLogin) { $userEntity = $repo->findOneBy(['username' => $userLogin]); if ($userEntity) { return $userEntity; } return $repo->findOneBy(['email' => $userLogin]); }
/** * Get a user, specified by ID, username or email address. * * @param integer|string $userId * * @return array|false */ public function getUser($userId) { if ($userEntity = $this->repository->getUser($userId)) { $userEntity->setPassword('**dontchange**'); return $userEntity->toArray(); } return false; }
/** * Get a user, specified by ID, username or email address. * * @param integer|string $userId * * @return array|false */ public function getUser($userId) { // Make sure users have been 'got' already. $this->getUsers(); // In most cases by far, we'll request an ID, and we can return it here. if (array_key_exists($userId, $this->users)) { return $this->users[$userId]; } // Fallback: See if we can get it by username or email address. if ($userEntity = $this->repository->getUser($userId)) { $userEntity->setPassword('**dontchange**'); return $userEntity->toArray(); } return false; }
/** * Get a user, specified by ID, username or email address. * * @param integer|string $userId * * @return array|false */ public function getUser($userId) { // Make sure users have been 'got' already. $this->getUsers(); // In most cases by far, we'll request an ID, and we can return it here. if (array_key_exists($userId, $this->users)) { return $this->users[$userId]; } // Fallback: See if we can get it by username or email address. try { if ($userEntity = $this->repository->getUser($userId)) { return $userEntity->toArray(); } } catch (TableNotFoundException $e) { return false; } return false; }
/** * Check the user authentication cookie against what is stored in the * database. * * @param string $authCookie * * @return boolean */ protected function checkSessionDatabase($authCookie) { $userAgent = $this->cookieOptions['browseragent'] ? $this->userAgent : null; if (!($authTokenEntity = $this->repositoryAuthtoken->getToken($authCookie, $this->remoteIP, $userAgent))) { return false; } if (!($databaseUser = $this->repositoryUsers->getUser($authTokenEntity->getUsername()))) { return false; } // Update session data $sessionAuth = new Token\Token($databaseUser, $authTokenEntity); $this->session->set('authentication', $sessionAuth); // Check if user is _still_ allowed to log on. if (!$this->permissions->isAllowed('login', $sessionAuth->getUser()->toArray(), null) || !$sessionAuth->isEnabled()) { $this->systemLogger->error('User ' . $sessionAuth->getUser()->getUserName() . ' has been disabled and can not login.', ['event' => 'authentication']); return false; } return $this->checkSessionKeys($sessionAuth); }