private function authenticateWithToken($token) { $user = $this->userModel->getUserByTokenAuth($token); if (!empty($user['login'])) { return $this->authenticationSuccess($user); } return new AuthResult(AuthResult::FAILURE, null, $token); }
/** * Authenticates user * * @return AuthResult */ public function authenticate() { if (!empty($this->md5Password)) { // favor authenticating by password $this->token_auth = UsersManagerAPI::getInstance()->getTokenAuth($this->login, $this->getTokenAuthSecret()); } if (is_null($this->login)) { $model = new Model(); $user = $model->getUserByTokenAuth($this->token_auth); if (!empty($user['login'])) { $code = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS; return new AuthResult($code, $user['login'], $this->token_auth); } } else { if (!empty($this->login)) { $model = new Model(); $user = $model->getUser($this->login); if (!empty($user['token_auth']) && (SessionInitializer::getHashTokenAuth($this->login, $user['token_auth']) === $this->token_auth || $user['token_auth'] === $this->token_auth)) { $this->setTokenAuth($user['token_auth']); $code = !empty($user['superuser_access']) ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS; return new AuthResult($code, $this->login, $user['token_auth']); } } } return new AuthResult(AuthResult::FAILURE, $this->login, $this->token_auth); }
protected function getUserForLogin() { if (empty($this->userForLogin)) { if (!empty($this->login)) { $this->userForLogin = $this->usersModel->getUser($this->login); } else { if (!empty($this->token_auth)) { $this->userForLogin = $this->usersModel->getUserByTokenAuth($this->token_auth); } else { throw new Exception("Cannot get user details, neither login nor token auth are set."); } } } return $this->userForLogin; }
/** * Authenticates user * * @return AuthResult */ public function authenticate() { $logger = StaticContainer::get('Psr\\Log\\LoggerInterface'); $model = new Model(); $user = $model->getUser($this->login); if (!$user) { $user = $model->getUserByTokenAuth($this->token_auth); if (!$user) { $logger->info("Creating user " . $this->login); $model->addUser($this->login, $this->getTokenAuthSecret(), $this->email, $this->alias, $this->token_auth, Date::now()->getDatetime()); $user = $model->getUser($this->login); } } $accessCode = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS; $this->login = $user['login']; if ($this->getViewableUserStatus() || $this->getSuperUserStatus()) { $site_ids = $this->getDefaultSiteIds(); $current_accesses = array(); foreach ($site_ids as $site_id) { $accesses = $model->getUsersAccessFromSite($site_id); foreach ($accesses as $user => $access) { if ($this->login == $user && ($access == "view" || $access == 'admin')) { $current_accesses[] = $site_id; } } } $new_accesses = array(); foreach ($site_ids as $site_id) { if (!in_array($site_id, $current_accesses)) { $new_accesses[] = $site_id; } } if (count($new_accesses) > 0) { $logger->info("Adding default site ids to " . $this->login); $model->addUserAccess($this->login, "view", $new_accesses); } } $is_superuser = $this->getSuperUserStatus(); $model->setSuperUserAccess($this->login, $is_superuser); return new AuthResult($accessCode, $this->login, $this->token_auth); }
/** * Authenticates user * * @return AuthResult */ public function authenticate() { if (is_null($this->login)) { $model = new Model(); $user = $model->getUserByTokenAuth($this->token_auth); if (!empty($user['login'])) { $code = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS; return new AuthResult($code, $user['login'], $this->token_auth); } } else { if (!empty($this->login)) { $model = new Model(); $user = $model->getUser($this->login); if (!empty($user['token_auth']) && ($this->getHashTokenAuth($this->login, $user['token_auth']) === $this->token_auth || $user['token_auth'] === $this->token_auth)) { $this->setTokenAuth($user['token_auth']); $code = !empty($user['superuser_access']) ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS; return new AuthResult($code, $this->login, $user['token_auth']); } } } return new AuthResult(AuthResult::FAILURE, $this->login, $this->token_auth); }