首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Moodle ByPass登录屏幕

Moodle ByPass登录屏幕
EN

Stack Overflow用户
提问于 2014-03-15 00:51:08
回答 2查看 3.1K关注 0票数 1

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

我已经创建了一个插件,它应该绕过这个屏幕,但它不工作。我不确定我是否遗漏了什么,或者文件的格式不正确:

代码语言:javascript
复制
<?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;
}

}

?>

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

发布于 2014-03-15 17:48:24

我猜你已经通过wiki创建了一个身份验证插件-- http://docs.moodle.org/dev/Authentication_plugins

我想知道它是不是启用了?

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

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

票数 3
EN

Stack Overflow用户

发布于 2014-03-17 21:19:15

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

代码语言:javascript
复制
<?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;
}

}

?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22411149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档