Skip to content
Snippets Groups Projects
Commit f1c917eb authored by Julian's avatar Julian
Browse files

In-request caching of getUserData requests

parent 697165fe
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin
{
parent::__construct();
$this->cando['external'] = true;
$this->api_client = null;
$this->api_user_cache = array();
}
private function getOAuth2RedirectURI()
......@@ -136,23 +138,32 @@ class auth_plugin_authuffd extends DokuWiki_Auth_Plugin
{
if ($_SESSION[DOKU_COOKIE]['auth']['user'] == $user)
return $_SESSION[DOKU_COOKIE]['auth']['info'];
$http = new DokuHTTPClient;
$http->keep_alive = false;
$http->user = $this->getConf('api_username');
$http->pass = $this->getConf('api_password');
if (!$this->api_client)
{
$this->api_client = new DokuHTTPClient;
$this->api_client->user = $this->getConf('api_username');
$this->api_client->pass = $this->getConf('api_password');
}
if (isset($this->api_user_cache[$user]))
return $this->api_user_cache[$user];
$params = array(
'loginname' => $user
);
$ok = $http->get($this->getConf('baseurl') . '/api/v1/getusers?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986));
if (!$ok || $http->status != 200)
$ok = $this->api_client->get($this->getConf('baseurl') . '/api/v1/getusers?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986));
if (!$ok || $this->api_client->status != 200)
return false;
$results = json_decode($http->resp_body);
if (!$results)
return false;
return array(
$results = json_decode($this->api_client->resp_body);
$result = false;
if ($results)
{
$result = array(
'name' => $results[0]->displayname,
'mail' => $results[0]->email,
'grps' => $results[0]->groups,
);
}
$this->api_user_cache[$user] = $result;
return $result;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment