We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 5eb0dac5 authored by Jonas Haraldsson's avatar Jonas Haraldsson

function Server::getAuthToken()

Create Server::getAuthToken(),
and make ws method auth.gettoken use it
parent 3977c0cb
......@@ -706,20 +706,14 @@ function method_album_getTags() {
* @api
*/
function method_auth_getToken() {
global $adodb;
$key = md5(time() . rand());
$token = Server::getAuthToken();
try {
$result = $adodb->Execute('INSERT INTO Auth (token, expires) VALUES ('
. $adodb->qstr($key) . ', '
. (int)(time() + 3600)
. ')');
} catch (Exception $e) {
if(!$token) {
report_failure(LFM_SERVICE_OFFLINE);
}
$xml = simplexml_load_string('<lfm status="ok"><token>' . $key . '</token></lfm>');
$xml = simplexml_load_string('<lfm status="ok"><token>' . $token . '</token></lfm>');
respond($xml);
}
/**
......
......@@ -931,4 +931,25 @@ class Server {
return $result;
}
/**
* Create a random authentication token and return it
*
* @return string Token.
*/
static function getAuthToken() {
global $adodb;
$key = md5(time() . rand());
$expires = (int) (time() + 3600);
$query = 'INSERT INTO Auth(token, expires) VALUES(?,?)';
$params = array($key, $expires);
try {
$adodb->Execute($query, $params);
return $key;
} catch (Exception $e) {
reportError($e->getMessage(), $e->getTraceAsString());
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment