catalyst/moodle-auth_userkey

Timeout error 30 seconds

Closed this issue · 2 comments

Because it takes to enter moodle, it shows error after 30 seconds. How can I solve it, will it be the curl?

/**

  • @param string $useremail Email address of user to create token for.
  • @param string $firstname First name of user (used to update/create user).
  • @param string $lastname Last name of user (used to update/create user).
  • @param string $username Username of user (used to update/create user).
  • @param string $ipaddress IP address of end user that login request will come from (probably $_SERVER['REMOTE_ADDR']).
  • @param int $courseid Course id to send logged in users to, defaults to site home.
  • @param int $modname Name of course module to send users to, defaults to none.
  • @param int $activityid cmid to send logged in users to, defaults to site home.
  • @return bool|string
    */

function getloginurl($useremail, $firstname, $lastname, $username, $courseid = null, $modname = null, $activityid = null) {
require_once('curl.php');

$token        = 'mytoken';//editar token que generamos
$domainname   = 'myurl';//colocar la url de la plataforma
$functionname = 'auth_userkey_request_login_url';

$params = Array('user' => Array('email' => $useremail) );

/*
$param = [
'user' => [
'email' => $useremail
]
];
*/

$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname . '&moodlewsrestformat=json';

// $serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;
// echo $serverurl;
$curl = new curl; // The required library curl can be obtained from https://github.com/moodlehq/sample-ws-clients

try {

$resp = $curl->post($serverurl, $params);

    echo $resp."<br><br>";
    $resp     = json_decode($resp);
    print_r($resp);
   
    if ($resp && !empty($resp->loginurl)) {
        $loginurl = $resp->loginurl;
        echo "<br><br>$loginurl<br><br>";
     //   exit;
    }

} catch (Exception $ex) {
    return false;
}

if (!isset($loginurl)) {
    return false;
}

$path = '';
if (isset($courseid)) {
    $path = '&wantsurl=' . urlencode("$domainname/course/view.php?id=$courseid");
    
    $path=str_replace("%3A", ":", "$path");
    $path=str_replace("%2F", "/", "$path");
    $path=str_replace("//course", "/course", "$path");
    $path=str_replace("%3F", "?", "$path");
    $path=str_replace("%3D", "=", "$path");

// echo "$path

";
}
/*
if (isset($modname) && isset($activityid)) {
$path = '&wantsurl=' . urlencode("$domainname/mod/$modname/view.php?id=$activityid");
}

echo "$path<br><br>";
echo $loginurl.$path;

*/
return $loginurl.$path;
}

$mail=$_GET['email'];
$cid=$_GET['courseid'];
$url = getloginurl("$mail", 'Carlos', 'Legorreta Garcia', 'carlos.legorreta', $cid, null, null);

header('Location: '.$url);
die();

Hi @danielddltellez
Thank you for using this plugin.
First of all you should figure out why your request takes 30 seconds. It shouldn't be that long on normally working moodle instances.

closing this one as I can't replicate it. Most likely the issue in the moodle instance itself.