Moodle ByPass登录屏幕

时间:2014-03-14 16:51:08

标签: moodle

我正在尝试将Moodle整合到现有网站中。我有用户登录我的网站,并有一个选项从那里跳进Moodle。我想这样做,这样用户就不必输入用户名和密码了。

我创建了一个应该绕过此屏幕的插件,但它无效。我不确定我是否遗漏了某些内容或文件格式不正确:

<?php

require_once($CFG->libdir.'/authlib.php');

class auth_plugin_sentry extends auth_plugin_base {

function auth_plugin_sentry() {
    $this->config = get_config('auth/sentry');
    $this->authtype = 'sentry';
}

// We don't acutally auth anyone, we're just here for the hooks
function user_login ($username, $password) {
    return true;
}

    function config_form($config, $err, $user_fields) {
    include 'config.php';
}
function process_config($config) {
    // set to defaults if undefined
    if (!isset($config->host)) {
        $config->host = 'localhost';
    }
    if (!isset($config->type)) {
        $config->type = 'mysql';
    }
    if (!isset($config->sybasequoting)) {
        $config->sybasequoting = 0;
    }
    if (!isset($config->name)) {
        $config->name = '';
    }
    if (!isset($config->user)) {
        $config->user = '';
    }
    if (!isset($config->pass)) {
        $config->pass = '';
    }
    if (!isset($config->table)) {
        $config->table = '';
    }
    if (!isset($config->fielduser)) {
        $config->fielduser = '';
    }
    if (!isset($config->fieldpass)) {
        $config->fieldpass = '';
    }
    if (!isset($config->passtype)) {
        $config->passtype = 'plaintext';
    }
    if (!isset($config->extencoding)) {
        $config->extencoding = 'utf-8';
    }
    if (!isset($config->setupsql)) {
        $config->setupsql = '';
    }
    if (!isset($config->debugauthdb)) {
        $config->debugauthdb = 0;
    }
    if (!isset($config->removeuser)) {
        $config->removeuser = AUTH_REMOVEUSER_KEEP;
    }
    if (!isset($config->changepasswordurl)) {
        $config->changepasswordurl = '';
    }

    // Save settings.
    set_config('host',          $config->host,          'auth/db');
    set_config('type',          $config->type,          'auth/db');
    set_config('sybasequoting', $config->sybasequoting, 'auth/db');
    set_config('name',          $config->name,          'auth/db');
    set_config('user',          $config->user,          'auth/db');
    set_config('pass',          $config->pass,          'auth/db');
    set_config('table',         $config->table,         'auth/db');
    set_config('fielduser',     $config->fielduser,     'auth/db');
    set_config('fieldpass',     $config->fieldpass,     'auth/db');
    set_config('passtype',      $config->passtype,      'auth/db');
    set_config('extencoding',   trim($config->extencoding), 'auth/db');
    set_config('setupsql',      trim($config->setupsql),'auth/db');
    set_config('debugauthdb',   $config->debugauthdb,   'auth/db');
    set_config('removeuser',    $config->removeuser,    'auth/db');
    set_config('changepasswordurl', trim($config->changepasswordurl), 'auth/db');

    return true;
}

}

?>

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

我猜你已经通过维基创建了一个auth插件? http://docs.moodle.org/dev/Authentication_plugins

我想知道它是否已启用?

在网站管理员中 - &gt;插件 - &gt;认证

http://docs.moodle.org/26/en/Managing_authentication

答案 1 :(得分:1)

我发现了我的问题。我需要调用loginpage_hook函数。我现在从cookie中获取用户和密码,并将其发送到authenticate_user_login进行验证。

<?php

require_once($CFG->libdir.'/authlib.php');

class auth_plugin_sentry extends auth_plugin_base {

function auth_plugin_sentry() {
    $this->config = get_config('auth/sentry');
    $this->authtype = 'sentry';
}
function user_login($username, $password) {
    return false;
}

/**
 * Authentication hook - is called every time user hit the login page
 */
function loginpage_hook() {
    global $USER, $SESSION, $CFG, $DB;

    $username = $_COOKIE['STARUSER'];
    $password = $_COOKIE['STARPASS'];

    //$username = "admin";//$user->username;
    //$password = "Admin123!";

    //authenticate the user
    $user = authenticate_user_login($username, $password);
    if ($user) {
        complete_user_login($user);
        // Redirection
        // No wantsurl stored or external - go to homepage
        $urltogo = $CFG->wwwroot.'/';
        redirect($urltogo);
    }
    else
    {
        //if user authorize fails bounce back to user student portal with error
        header("Location: xxxxxxxxxxxxx");
    }
}

function config_form($config, $err, $user_fields) {
    include 'config.php';
}
function process_config($config) {
    // set to defaults if undefined
    if (!isset($config->host)) {
        $config->host = 'localhost';
    }
    if (!isset($config->type)) {
        $config->type = 'mysql';
    }
    if (!isset($config->sybasequoting)) {
        $config->sybasequoting = 0;
    }
    if (!isset($config->name)) {
        $config->name = '';
    }
    if (!isset($config->user)) {
        $config->user = '';
    }
    if (!isset($config->pass)) {
        $config->pass = '';
    }
    if (!isset($config->table)) {
        $config->table = '';
    }
    if (!isset($config->fielduser)) {
        $config->fielduser = '';
    }
    if (!isset($config->fieldpass)) {
        $config->fieldpass = '';
    }
    if (!isset($config->passtype)) {
        $config->passtype = 'plaintext';
    }
    if (!isset($config->extencoding)) {
        $config->extencoding = 'utf-8';
    }
    if (!isset($config->setupsql)) {
        $config->setupsql = '';
    }
    if (!isset($config->debugauthdb)) {
        $config->debugauthdb = 0;
    }
    if (!isset($config->removeuser)) {
        $config->removeuser = AUTH_REMOVEUSER_KEEP;
    }
    if (!isset($config->changepasswordurl)) {
        $config->changepasswordurl = '';
    }

    // Save settings.
    set_config('host',          $config->host,          'auth/db');
    set_config('type',          $config->type,          'auth/db');
    set_config('sybasequoting', $config->sybasequoting, 'auth/db');
    set_config('name',          $config->name,          'auth/db');
    set_config('user',          $config->user,          'auth/db');
    set_config('pass',          $config->pass,          'auth/db');
    set_config('table',         $config->table,         'auth/db');
    set_config('fielduser',     $config->fielduser,     'auth/db');
    set_config('fieldpass',     $config->fieldpass,     'auth/db');
    set_config('passtype',      $config->passtype,      'auth/db');
    set_config('extencoding',   trim($config->extencoding), 'auth/db');
    set_config('setupsql',      trim($config->setupsql),'auth/db');
    set_config('debugauthdb',   $config->debugauthdb,   'auth/db');
    set_config('removeuser',    $config->removeuser,    'auth/db');
    set_config('changepasswordurl', trim($config->changepasswordurl), 'auth/db');

    return true;
}

}

?>