dongxin9759 2014-09-24 09:23
浏览 59

Moodle php - moodle在哪里检查提供的注册密钥是否与课程的预定义注册密钥匹配?

I am creating a moodle website. I already setup my courses with their specific enrolment keys, etc. But I want to know in what .php file and where in that file (in the moodle files), does Moodle check if the enrollment key entered by the user matches what I set as the enrolment key for the course...

Thanks for your help!

UPDATE-------- I did as Russell England suggested, but when I go to the page where I type my enrolment key, the page isn't loading or the page is redirected to my moodle homepage. My table that I store the enrolment keys is user_enrolment_keys.

Here is the updated validation function:

 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
}
  • 写回答

1条回答 默认 最新

  • douxi3233 2014-09-24 09:54
    关注

    Its validated in the custom self enrolment form

    In the function validation() in the file /enrol/self/locallib.php it checks if the password matches and displays an error if not.

    UPDATE:

    I would probably do this in the validation function

    Add the $USER variable at the top

    global $DB, $CFG, $USER;
    

    Then check if the user, course and password combination exists in your newly created licence table ;)

    $params = array('userid' => $USER->id, 'courseid' => $instance->courseid, 'password' => $data['enrolpassword']); 
    if (!$DB->record_exists('local_licence_table', $params)) {
        $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
        return $errors;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)