Forums | Mahara Community

Developers /
Creating a new user automatically


anonymous profile picture
Account deleted
Posts: 1

06 November 2012, 1:58

hi!

We will be piloting out mahara 1.6 for our University this academic year. SSO is set up on all our services and we were looking into the possibility of also including Mahara.

Code has been added within mahara's config.php so that we can identify if a user (apache remote user) is already signed in and if the account exists within mahara.  The problem that we are encountering is when a user is signed in to the sso but the user does not have an account within mahara yet! For this reason we will need create the user within mahara.

We wish that the user's account is created automatically (when user visits mahara the first time) and not to upload users via csv file.

Could you please help by indicating which function/s are needed in order to create the user account within mahara?

so far within config:

$thisUser['username'] = 'personsusername'; //from server remote user

function local_init_user() {
    global $thisUser; //array containing user details (not from mahara)
        global $USER, $SESSION;

    if ( $USER->is_logged_in() ){
        if ($USER->get('username') != $thisUser['username']) {
            $USER->logout();
                        loginUser();
        }

    } else {
        loginUser();
    }

} //end function


function loginUser(){
    global $thisUser, $USER, $SESSION;


    try {
        $USER=$USER->find_by_username($thisUser['username']);       
    } catch (Exception $e) {

        /*
        Code to create new user
        */       
    }


    $USER->login($thisUser['username'], 'passwordforuser');
    $USER->commit();
}


local_init_user() is called within init.php just after $USER    = new LiveUser();

thank you
Dorian

Kristina Hoeppner's profile picture
Posts: 4717

06 November 2012, 12:24

Hello Dorian,

Why would you need a special setting in the config.php? The built-in SAML SSO plugin allows you to auto-create users if they don't already exist.

http://manual.mahara.org/en/1.6/administration/institutions.html#saml-authentication (number 8 in the screenshot)

Or are you using a different SSO plugin?

Cheers

Kristina

2 results