/** * * @param int $userId * @return bool * @throws NotAuthenticatedException * @throws UserNotFoundException */ public function isAdmin($userId = null) { if (is_null($userId)) { $currentUser = UserContext::getInstance()->userInfo(); if ($currentUser === false) { throw new NotAuthenticatedException(); } $userId = $currentUser[$this->getUserTable()->id]; } $user = $this->getById($userId); if (!is_null($user)) { return preg_match('/^(yes|YES|[yY]|true|TRUE|[tT]|1|[sS])$/', $user->getField($this->getUserTable()->admin)) === 1; } else { throw new UserNotFoundException("Cannot find the user"); } }
<?php require "vendor/autoload.php"; $users = new ByJG\Authenticate\UsersAnyDataset('/tmp/pass.anydata.xml'); $users->addUser('Some User Full Name', 'someuser', '*****@*****.**', '12345'); //$users->save(); $user = $users->isValidUser('someuser', '12345'); var_dump($user); if (!is_null($user)) { \ByJG\Authenticate\UserContext::getInstance()->registerLogin($userId); echo "Authenticated: " . \ByJG\Authenticate\UserContext::getInstance()->isAuthenticated(); print_r(\ByJG\Authenticate\UserContext::getInstance()->userInfo()); }
/** * Make login in XMLNuke Engine * @access public * @param string $user * @return void */ public function MakeLogin($user, $id) { $userObj = $this->getUsersDatabase()->getById($id); UserContext::getInstance()->registerLogin($userObj->toArray()); }