Username Change with External Database Authentication

Re: Username Change with External Database Authentication

by David Aylmer -
Number of replies: 2

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... 

In reply to David Aylmer

Re: Username Change with External Database Authentication

by Lluís Forns Puigmartí -

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