0
我正在創建一個moodle網站。我已經用他們特定的註冊密鑰等設置了我的課程。但是我想知道什麼.php文件以及該文件中的哪些位置(在moodle文件中),Moodle會檢查用戶輸入的註冊密鑰是否與我設置的匹配作爲課程的註冊密鑰...Moodle php - moodle在哪裏檢查提供的註冊密鑰是否與課程的預定義註冊密鑰相匹配?
感謝您的幫助!
UPDATE -------- 我按照羅素英格蘭的建議做了,但是當我進入我輸入我的註冊碼的頁面時,頁面沒有加載或頁面被重定向到我的moodle主頁。我存儲註冊密鑰的表是user_enrolment_keys。
這裏是更新的驗證功能:
public function validation($data, $files) {
global $DB, $CFG, $USER;
$errors = parent::validation($data, $files);
$instance = $this->instance;
if ($this->toomany) {
$errors['notice'] = get_string('error');
return $errors;
}
//--------Russell's suggestion--------------
if ($instance->password) {
$params = array('user_email' => $USER->email, 'course_id' => $instance->courseid, 'enrolment_key' => $data['enrolpassword']);
if (!$DB->record_exists('user_enrolment_keys', $params)) {
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
return $errors;
}
}
//What I tried last (did not work either)...
/*$uemail = $USER->email;
$userscoursekey = 'testing';
$connecty = mysqli_connect("localhost", "...", "...", "...");
mysql_select_db('user_enrolment_keys', $connecty);
$var2 = $instance->courseid;
$resulty = mysqli_query($connecty, "SELECT * FROM user_enrolment_keys WHERE user_email='$uemail' AND course_id='$var2'");
$numrows = $resulty->num_rows;
if($numrows > 0)
{
while($row = mysqli_fetch_assoc($resulty))
{
$userscoursekey = $row['enrolment_key'];
}
}
$instance->password = $userscoursekey;
my_sqli_close($connecty); //Close the database connection.*/
if ($instance->password) {
if ($data['enrolpassword'] !== $instance->password) {
if ($instance->customint1) {
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id ASC', 'id, enrolmentkey');
$found = false;
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data['enrolpassword']) {
$found = true;
break;
}
}
if (!$found) {
// We can not hint because there are probably multiple passwords.
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}
} else {
$plugin = enrol_get_plugin('self');
if ($plugin->get_config('showhint')) {
$hint = core_text::substr($instance->password, 0, 1);
$errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint);
} else {
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}
}
}
}
return $errors;
// END DEFAULT BLOCK
}
謝謝!我會試試看,基本上,我創建了一個新的PHP文件(在個人支付我的課程後顯示),創建一個特定於該用戶和該課程的新註冊密鑰 - 以避免欺詐使用相同的註冊密鑰註冊。所以在函數驗證中,我試圖獲得我分配給用戶的密鑰(付款後),並檢查它是否與鍵入的鍵相匹配...有關如何從我創建的數據庫中檢索密碼的任何建議函數驗證?感謝您的快速幫助! – 2014-09-24 09:59:06
更新了答案 – 2014-09-24 10:20:10
嗨,羅素英格蘭先生,請幫助我再次更新... – 2014-09-24 17:58:33