Commit 1e1d7725 authored by Astor Bizard's avatar Astor Bizard
Browse files

Webservice link now uses permanent token, and generates it using standard...

Webservice link now uses permanent token, and generates it using standard webservice token generation.
parent 058b73ef
......@@ -936,39 +936,15 @@ function vpl_get_webservice_token($vpl) {
'externalserviceid' => $service->id
) );
if (! empty( $tokenrecord ) and $tokenrecord->validuntil > 0 and $tokenrecord->validuntil < $now) {
unset( $tokenrecord ); // Will be delete before creating a new one.
unset( $tokenrecord ); // Will be deleted before creating a new one.
}
if (empty( $tokenrecord )) {
// Remove old tokens from DB.
$select = 'validuntil > 0 AND validuntil < ?';
$DB->delete_records_select( 'external_tokens', $select, array (
$now
$webservice = new webservice();
$webservice->generate_user_ws_tokens($USER->id);
$tokenrecord = $DB->get_record( 'external_tokens', array (
'userid' => $USER->id,
'externalserviceid' => $service->id
) );
// Generate unique token.
for ($i = 0; $i < 100; $i ++) {
$token = md5( uniqid( mt_rand(), true ) );
$tokenrecord = $DB->get_record( 'external_tokens', array (
'token' => $token
) );
if (empty( $tokenrecord )) {
break;
}
}
if ($i >= 100) {
return '';
}
$tokenrecord = new stdClass();
$tokenrecord->token = $token;
$tokenrecord->sid = session_id();
$tokenrecord->userid = $USER->id;
$tokenrecord->creatorid = $USER->id;
$tokenrecord->tokentype = EXTERNAL_TOKEN_EMBEDDED;
$tokenrecord->timecreated = $now;
$tokenrecord->validuntil = $now + DAYSECS;
$tokenrecord->iprestriction = getremoteaddr();
$tokenrecord->contextid = $vpl->get_context()->id;
$tokenrecord->externalserviceid = $service->id;
$DB->insert_record( 'external_tokens', $tokenrecord );
}
return $tokenrecord->token;
}
......
Supports Markdown
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