Skip to content
Snippets Groups Projects
Commit 7d3c8d42 authored by Gabriel Birke's avatar Gabriel Birke
Browse files

Wrap user modifications in events

Adds a wrapper function in the basic auth class which is used by the core code
to modify the user database. The wrapper function signals events and delegates
the action to the auth backend.

darcs-hash:20080817141121-79ce3-3300a4342b62a7a18ebcc9a765d87b30a0264621.gz
parent e7835c60
No related branches found
No related tags found
No related merge requests found
......@@ -630,7 +630,7 @@ function register(){
}
//okay try to create the user
if(!$auth->createUser($_POST['login'],$pass,$_POST['fullname'],$_POST['email'])){
if(!$auth->triggerUserMod('create', array($_POST['login'],$pass,$_POST['fullname'],$_POST['email']))){
msg($lang['reguexists'],-1);
return false;
}
......@@ -715,7 +715,7 @@ function updateprofile() {
}
}
return $auth->modifyUser($_SERVER['REMOTE_USER'], $changes);
return $auth->triggerUserMod('modify', array($_SERVER['REMOTE_USER'], $changes));
}
/**
......@@ -764,7 +764,7 @@ function act_resendpwd(){
}
$pass = auth_pwgen();
if (!$auth->modifyUser($user,array('pass' => $pass))) {
if (!$auth->triggerUserMod('modify', array($user,array('pass' => $pass)))) {
msg('error modifying user data',-1);
return false;
}
......
......@@ -89,6 +89,38 @@ class auth_basic {
}
}
/**
* Trigger the AUTH_USERDATA_CHANGE event and call the modification function. [ DO NOT OVERRIDE ]
*
* You should use this function instead of calling createUser, modifyUser or
* deleteUsers directly. The event handlers can prevent the modification, for
* example for enforcing a user name schema.
*
* @author Gabriel Birke <birke@d-scribe.de>
* @param string $type Modification type ('create', 'modify', 'delete')
* @param array $params Parameters for the createUser, modifyUser or deleteUsers method. The content of this array depends on the modification type
* @return mixed Result from the modification function or false if an event handler has canceled the action
*/
function triggerUserMod($type, $params)
{
$validTypes = array(
'create' => 'createUser',
'modify' => 'modifyUser',
'delete' => 'deleteUsers'
);
if(empty($validTypes[$type]))
return false;
$eventdata = array('type' => $type, 'params' => $params, 'modification_result' => null);
$evt = new Doku_Event('AUTH_USER_CHANGE', $eventdata);
if ($evt->advise_before(true)) {
$result = call_user_func_array(array($this, $validTypes[$type]), $params);
$evt->data['modification_result'] = $result;
}
$evt->advise_after();
unset($evt);
return $result;
}
/**
* Log off the current user [ OPTIONAL ]
*
......@@ -290,6 +322,7 @@ class auth_basic {
return array();
}
/**
* Check Session Cache validity [implement only where required/possible]
*
......
......@@ -346,7 +346,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return false;
}
if ($ok = $this->_auth->createUser($user,$pass,$name,$mail,$grps)) {
if ($ok = $this->_auth->triggerUserMod('create', array($user,$pass,$name,$mail,$grps))) {
msg($this->lang['add_ok'], 1);
......@@ -373,7 +373,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
if (!is_array($selected) || empty($selected)) return false;
$selected = array_keys($selected);
$count = $this->_auth->deleteUsers($selected);
$count = $this->_auth->triggerUserMod('delete', array($selected));
if ($count == count($selected)) {
$text = str_replace('%d', $count, $this->lang['delete_ok']);
msg("$text.", 1);
......@@ -454,7 +454,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
if (!empty($newgrps) && $this->_auth->canDo('modGroups') && $newgrps != $oldinfo['grps'])
$changes['grps'] = $newgrps;
if ($ok = $this->_auth->modifyUser($olduser, $changes)) {
if ($ok = $this->_auth->triggerUserMod('modify', array($olduser, $changes))) {
msg($this->lang['update_ok'],1);
if (!empty($_REQUEST['usernotify']) && $newpass) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment