Moodle Auth Plugin

Moodle Auth Plugin

by John Everden -
Number of replies: 3
I'm attempting to create an Auth Plugin that will allow the username to matched against additional fields in the database. I'm able to get it past Authentication but the User I login in with is essentially blank. To accomplish what I have accomplished to far I added a method to my new plugin

public function user_login($username, $password) {
global $CFG, $DB;
return false;
// Validate the login by using the Moodle user table.
// Remove if a different authentication method is desired.

$user = $DB->get_record_sql(
"
SELECT * FROM mdl_user where id IN (
SELECT
userid
FROM `mdl_user_info_data`
WHERE fieldid IN (
SELECT id FROM `mdl_user_info_field` WHERE shortname = 'additionalemail1'
or shortname = 'additionalemail2'
or shortname = 'additionalemail3'
or shortname = 'additionalemail4'
)
and data = ?
)
",
array($username)
);
// User does not exist.
if (!$user) {
return false;
}
return validate_internal_user_password($user, $password);
}
I've tried adding methods for get_userinfo and user_exists still with no luck.


Average of ratings: -
In reply to John Everden

Re: Moodle Auth Plugin

by Daniel Miranda -

You should use a nologin as base.

The methods you need to implement are:

// Verify if user exists

$is_user = $DB->get_record('user', array('uid'));

if (!$is_user) { 

    $is_user = create_user_record($uid, $password, $this->authtype); 

}

if ($is_user) {

    $USER = get_complete_user_data('username', $is_user->username);

} else {

    $this->error_page(get_string('error_create_user', self::COMPONENT_NAME));

}

public function do_login($urltogo) {

        global $USER, $CFG;

        complete_user_login($USER);

        $USER->loggedin = true;

        $USER->site = $CFG->wwwroot;

        set_moodle_cookie($USER->username);


        /**

         * If we are not on the page we want, then redirect to it.

         */

        if (qualified_me() !== $urltogo) {

            redirect($urltogo);

            exit;

        }

}


try to read the auth.php from my saml2 auth plugin and understand the procedure to authenticate a user

https://moodle.org/plugins/auth_saml2sso

In reply to Daniel Miranda

Re: Moodle Auth Plugin

by amit jadhv -

Dear Team,


I have facing below issue...plz suggest me.

Moodle 2.9 

Cannot use POP3 authentication. The PHP IMAP module is not installed.

More information about this error


Regards,

Amit Anant Jadhav.