我正在尝试使用身份验证插件手动对 moodle 中的用户进行身份验证,但我不了解整个过程正常工作所需的一切。所以,关于我在这里缺少的一些建议会非常有帮助!
我创建了插件,启用了它,它工作了,但仅适用于某些情况,这就是我的问题所在。我的猜测是,在某些时候,我需要实际调用一个将用户信息保存在 moodle 数据库中的函数。但同样,我不确定它在哪里,或者它是如何工作的。所以...专家,帮我一把。
这是我在身份验证插件上更改的两个功能。(auth.php)
function loginpage_hook() {
global $CFG, $DB, $user, $frm, $errormsg;
$IsAuthenticated = false;
if(isset($_COOKIE["AUTHENTICATION_KEY"])){
$json = file_get_contents("WWW.WEBSERVICEURL.COM",true);
//getting the file content
$decode = json_decode($json, true);
//getting the file content as array
if($decode["AuthFlag"]){
$ucUser = $decode["Username"];
$user = $DB->get_record('user', array('username'=>$ucUser, 'mnethostid'=>$CFG->mnet_localhost_id));
$frm->username = $ucUser;
$IsAuthenticated = true;
}
}
if(!$IsAuthenticated && empty($frm->username)){
$errormsg = ".";
}
}
/**
* Returns true if the username and password work or don't exist and false
* if the user exists and the password is wrong.
*
* @param string $username The username
* @param string $password The password
* @return bool Authentication success or failure.
*/
function user_login ($username, $password) {
global $CFG, $DB, $user;
if(!$user){ return false; }
if(isset($_COOKIE["AUTHENTICATION_KEY"])){
$json = file_get_contents("WWW.WEBSERVICEURL.COM", true);
//getting the file content
$decode = json_decode($json, true);
//getting the file content as array
if($decode["AuthFlag"]){
$ucUser = $decode["Username"];
if($user->username = $ucUser){ return true; }
}
}
return false;
}