Moodle旁路登录屏幕

Moodle旁路登录屏幕,moodle,Moodle,我正在尝试将Moodle集成到现有的网站中。我让用户登录到我的网站,从那里可以选择跳入Moodle。我想使用户不必输入用户名和密码 我已经创建了一个插件,应该绕过这个屏幕,但它不工作。我不确定是否丢失了某些内容或文件格式不正确: <?php require_once($CFG->libdir.'/authlib.php'); class auth_plugin_sentry extends auth_plugin_base { function auth_plugin_sent

我正在尝试将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;
}

}

?>


谢谢你的帮助

我猜你已经通过wiki创建了一个auth插件了吧

我想知道它是否启用了

在站点管理->插件->身份验证中


我猜你已经通过wiki创建了一个auth插件了吧

我想知道它是否启用了

在站点管理->插件->身份验证中


我发现了我的问题。我需要调用loginpage_hook函数。我现在从cookie中获取用户和密码,并将其发送到authenticate\u user\u 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;
}

}

?>

我发现了我的问题。我需要调用loginpage_hook函数。我现在从cookie中获取用户和密码,并将其发送到authenticate\u user\u 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;
}

}

?>


我已经查看了创建和启用插件的文档,但它仍然不起作用。我可以进入我的身份验证插件,看到我的已启用,但我仍然会看到登录屏幕。不确定我是否可以进一步提供帮助,但您可能希望查看一些集成插件的源代码-我已经查看了创建和启用插件的文档,但它仍然不起作用。我可以进入我的身份验证插件,并看到我的已启用,但我仍然得到登录屏幕。不确定我是否可以进一步帮助您,但您可能想看看一些集成插件的来源-超级!很高兴你把它分类了。太好了!很高兴你把它分类了。