Permalink
Browse files

add post_login and post_logout hooks

  • Loading branch information...
1 parent 0f78256 commit b035e148ba44f335daee62a07e520c20a0628894 Dieter Plaetinck committed with Dieterbe Jun 4, 2010
Showing with 52 additions and 4 deletions.
  1. +36 −0 hooks/functions/example.php
  2. +7 −2 htdocs/login.php
  3. +2 −0 htdocs/login_form.php
  4. +7 −2 htdocs/logout.php
View
36 hooks/functions/example.php
@@ -38,6 +38,42 @@ function example_post_session_init() {
add_hook('post_session_init','example_post_session_init');
/**
+ * The post_login function is called after the user has (tried to) login.
+ *
+ * Arguments available are:
+ * @param boolean Success
+ */
+function example_post_login() {
+ $args = func_get_args();
+
+ system_message(array(
+ 'title'=>sprintf('Hook called [%s]',__METHOD__),
+ 'body'=>sprintf('<i>Global Vars</i>: <small>%s</small>',join('| ',array_keys($GLOBALS))),
+ 'type'=>'info','special'=>true));
+
+ return true;
+}
+add_hook('post_login','example_post_login');
+
+/**
+ * The post_logout function is called after the user has (tried to) logout.
+ *
+ * Arguments available are:
+ * @param boolean Success
+ */
+function example_post_logout() {
+ $args = func_get_args();
+
+ system_message(array(
+ 'title'=>sprintf('Hook called [%s]',__METHOD__),
+ 'body'=>sprintf('<i>Global Vars</i>: <small>%s</small>',join('| ',array_keys($GLOBALS))),
+ 'type'=>'info','special'=>true));
+
+ return true;
+}
+add_hook('post_logout','example_post_logout');
+
+/**
* This pre_connect function is called before making a connection to the LDAP server.
* While PLA makes many calls to connect to the LDAP server, this is called only once
* when caching is turned on.
View
9 htdocs/login.php
@@ -22,16 +22,21 @@
'type'=>'warn'),
sprintf('cmd.php?cmd=login_form&server_id=%s',get_request('server_id','REQUEST')));
-if ($app['server']->login($user['login'],$user['password'],'user'))
+if ($app['server']->login($user['login'],$user['password'],'user')) {
+ if (function_exists('run_hook'))
+ run_hook('post_login',array('success'=> true));
system_message(array(
'title'=>_('Authenticate to server'),
'body'=>_('Successfully logged into server.'),
'type'=>'info'),
sprintf('cmd.php?server_id=%s',get_request('server_id','REQUEST')));
-else
+} else {
+ if (function_exists('run_hook'))
+ run_hook('post_login',array('success'=> false));
system_message(array(
'title'=>_('Failed to Authenticate to server'),
'body'=>_('Invalid Username or Password.'),
'type'=>'error'),
sprintf('cmd.php?cmd=login_form&server_id=%s',get_request('server_id','REQUEST')));
+}
?>
View
2 htdocs/login_form.php
@@ -34,6 +34,8 @@
# When we pop up the basic athentication, we come back to this script, so try the login again.
if ($app['server']->isLoggedIn('user')) {
+ if (function_exists('run_hook'))
+ run_hook('post_login',array('success'=> true));
system_message(array(
'title'=>_('Authenticate to server'),
'body'=>_('Successfully logged into server.'),
View
9 htdocs/logout.php
@@ -11,16 +11,21 @@
require './common.php';
-if ($app['server']->logout())
+if ($app['server']->logout()) {
+ if (function_exists('run_hook'))
+ run_hook('post_logout',array('success'=> true));
system_message(array(
'title'=>_('Authenticate to server'),
'body'=>_('Successfully logged out of server.'),
'type'=>'info'),
sprintf('index.php?server_id=%s',$app['server']->getIndex()));
-else
+} else {
+ if (function_exists('run_hook'))
+ run_hook('post_logout',array('success'=> false));
system_message(array(
'title'=>_('Failed to Logout of server'),
'body'=>_('Please report this error to the admins.'),
'type'=>'error'),
sprintf('index.php?server_id=%s',$app['server']->getIndex()));
+}
?>

0 comments on commit b035e14

Please sign in to comment.