Authentication

 
 
Picture of David Aylmer
Re: Username Change with External Database Authentication
 

Thinking about this again. To get around this flaw, you could potentially add a database trigger to update the original record with the new username if the idnumber field matches. Just make sure you're populating mdl_user.idnumber with the primary key of your external database.

That could work. Probably better to fix the sync code though... 

 
Average of ratings: -
Picture of Lluís Forns Puigmartí
Re: Username Change with External Database Authentication
 

I was trying to change sync function to, prior to delete/disable a user, check if username was changed. But my function fails when trying to update username (database write error). Any hint?

                    //check if user changed username
                    $user_changed_name=FALSE;
                    if (!empty($user->idnumber)) {
                        $authdb = $this->db_init();
                        $sql="SELECT ".$this->config->field_map_idnumber." AS idnumber , ".$this->config->fielduser." AS username
                                                     FROM {$this->config->table}
                                                     WHERE ".$this->config->field_map_idnumber." = '".addslashes($user->idnumber)."'";
                        $rs = $authdb->GetRow($sql);
                        if ($rs) {
                            $updateuser = new stdClass();
                            $updateuser->id   = $user->id;
                            $updateuser->username = $rs['username'];
                         print_r($updateuser);
                            $authdb->update_record('user', $updateuser);
                            $user_changed_name = TRUE;
                          }
                          $authdb->Close();
                    }

 

I could post full file if needed

 

 
Average of ratings: -
Picture of Lluís Forns Puigmartí
Re: Username Change with External Database Authentication
 

I solved the problem. I added a bug and posted my solution (don't know if this is the best way to do so).

 

https://tracker.moodle.org/browse/MDL-41642

 
Average of ratings: -