Skip to content

Commit

Permalink
feature:2823 Add triggers for login system
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@20282 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jan 20, 2013
1 parent 3d81c8d commit ff5568a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/functions_user.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ function log_user($user_id, $remember_me)
$_SESSION['pwg_uid'] = (int)$user_id;

$user['id'] = $_SESSION['pwg_uid'];
trigger_action('user_login', $user['id']);
}

/*
Expand Down Expand Up @@ -1177,6 +1178,18 @@ function pwg_password_verify($password, $hash, $user_id=null)
*/
function try_log_user($username, $password, $remember_me)
{
return trigger_event('try_log_user', false, $username, $password, $remember_me);
}

add_event_handler('try_log_user', 'pwg_login', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);

function pwg_login($success, $username, $password, $remember_me)
{
if ($success===true)
{
return true;
}

// we force the session table to be clean
pwg_session_gc();

Expand All @@ -1203,6 +1216,9 @@ function try_log_user($username, $password, $remember_me)
function logout_user()
{
global $conf;

trigger_action('user_logout', @$_SESSION['pwg_uid']);

$_SESSION = array();
session_unset();
session_destroy();
Expand Down
19 changes: 19 additions & 0 deletions tools/triggers_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,25 @@
'vars' => array('bool', null, 'string', 'methodName', 'array', 'params'),
'files' => array('include\ws_core.inc.php (PwgServer::invoke)'),
),
array(
'name' => 'user_logout',
'type' => 'trigger_action',
'vars' => array('int', 'user_id'),
'files' => array('include\functions_user.inc.php (logout_user)'),
),
array(
'name' => 'user_login',
'type' => 'trigger_action',
'vars' => array('int', 'user_id'),
'files' => array('include\functions_user.inc.php (log_user)'),
),
array(
'name' => 'try_log_user',
'type' => 'trigger_event',
'vars' => array('boolean', 'success', 'string', 'username', 'string', 'password', 'bool', 'remember_me'),
'files' => array('include\functions_user.inc.php (try_log_user)'),
'infos' => 'Used by identification form to check user credentials and log user. If success is true, another login method already succeed. Return true if your method succeed.',
),
);
?>
<!DOCTYPE html>
Expand Down

0 comments on commit ff5568a

Please sign in to comment.