jleyva / moodle-local_ltiprovider

This is a local plugin for making Moodle a LTI provider tool
28 stars 26 forks source link

LTI User creation fails if not provided email or name. #24

Closed beauseverson closed 9 years ago

beauseverson commented 9 years ago

In the local_ltiprovider_populate function of locallib.php when a user is created but no email address or name is supplied this fails to fill out the user and instead redirects the moodle page to fill out the user's profile. Since this is used via the LTI service from other sites this should be able to create a use regardless. LTI documentation says that these fields do not need to be supplied if security settings override it. So the plugin should be able to support this.

You can fix it by changing lines 195-196 of locallib.php to:

    $user->firstname = isset($context->info['lis_person_name_given'])? $context->info['lis_person_name_given'] : $context->info['user_id'];
    $user->lastname = isset($context->info['lis_person_name_family'])? $context->info['lis_person_name_family']: $context->info['context_id'];

and then updating the getUserEmail function in blti.php to:

    function getUserEmail() {
        # set default email in the event privacy settings don't pass in email.
        $email = $this->info['user_id'] . "@ltiuser.com";

        if ( isset($this->info['lis_person_contact_email_primary']) ) $email = $this->info['lis_person_contact_email_primary']; 
        # Sakai Hack
        if ( isset($this->info['lis_person_contact_emailprimary']) ) $email = $this->info['lis_person_contact_emailprimary']; 

        return $email;
    }

I was going to set a pull request but our fork of the plugin has other changes not really needed for the plugin.

beauseverson commented 9 years ago

Update: Just created pull request #25 to resolve this issue from a fresh fork. Minimal changes will be applied.

jleyva commented 9 years ago

Thanks, I integrated these changes also in the 27 branch (version for Moodle 2.7 and onwards)