DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:event:auth_userdata_change

AUTH_USER_CHANGE

Description:
Intercept user data modifications before they are sent to the auth backend
DefaultAction:
Call createUser, modifyUser or deleteUsers methods of an auth class.
Preventable:
yes
Added:
2008-08-17

You can use this event for logging changes to user data, to enforce password security or to prevent unsuitable user names. It is signaled from method triggerUserMod in inc/auth/basic.class.php. This method should be called when modifying user data instead of calling createUser, modifyUser or deleteUsers directly.

Passed Data

An array is passed with the event object. Its exact composition differs between the three different AUTH_USER_CHANGE types (create, modify, delete).

  • $data['type'] - Type of data modification (create, modify, delete)
  • $data['params'] - Parameter array for the createUser, modifyUser or deleteUsers methods of an auth class.

Create

When a user is created, all of that user's information is sent with the event. These arrays are only index keyed.

array (
     ['type']   => 'create',
     ['params'] => 
          array (
               [0] => 'username',
               [1] => 'password',
               [2] => 'realname',
               [3] => 'e@mail.com',
               [4] => 
                    array (
                    [0] => 'group1',
                    [1] => 'group2',
               ),
          ),
     ['modification_result'] => 'password',
)
//Example usage:
$event->data['params'][0] = 'username'
$event->data['params'][1] = 'password'
$event->data['params'][4][0] = 'group1'

Modify

When a user is modified, only the changed entries are sent with the event. The user's pre-modification username is always accessible. The keys within the ['params'][1] array indicate which field was changed, and the values within the array contain the new information. When writing your plugins to intercept modifications, you will want to check to see which keys are set.

array (
     ['type']   => 'modify',
     ['params'] => 
     array (
          [0] => 'username',
          [1] => 
               array (
                    ['user'] => 'new_username',
                    ['pass'] => 'new_password',
                    ['name'] => 'new_realname',
                    ['mail'] => 'new_e@mail.com',
                    ['grps'] => 
                         array (
                              [0] => 'group1',
                              [1] => 'group2',
                         ),
               ),
     ),
     ['modification_result'] => true,
)
//Example usage:
$event->data['params'][0] = 'username'
$event->data['params'][1]['user'] = 'new_username'
$event->data['params'][1]['grps'][0] = 'group1'

Delete

When a user deleted, the event data generally only contains that user's username.

array (
     ['type']   => 'delete',
     ['params'] => 
          array (
               [0] => 
                    array (
                         [0] => 'username',
                    ),
          ),
     'modification_result' => 1,
)
//Example usage:
$event->data['params'][0][0] = 'username'

modification_result varies between the different event types. It is generally the result from the modification function or false if an event handler has canceled the action and can be used in the AFTER handler to run actions after a user has been successfully been modified.

See also

devel/event/auth_userdata_change.txt · Last modified: 2018-12-08 15:02 by torpedo

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki