cvs: pear /Auth Auth.php
| From: | Marko Karppinen | Date: | Sun, 25 Aug 2002 08:15:56 +0000 |
| Subject: | cvs: pear /Auth Auth.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5949@lists.php.net to get a copy of this message | ||
markonen Sun Aug 25 04:15:56 2002 EDT
Modified files:
/pear/Auth Auth.php
Log:
Add optional setLoginCallback() and setLogoutCallback() methods
Index: pear/Auth/Auth.php
diff -u pear/Auth/Auth.php:1.39 pear/Auth/Auth.php:1.40
--- pear/Auth/Auth.php:1.39 Sun Aug 25 01:13:10 2002
+++ pear/Auth/Auth.php Sun Aug 25 04:15:56 2002
@@ -16,7 +16,7 @@
// | Authors: Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Auth.php,v 1.39 2002/08/25 05:13:10 markonen Exp $
+// $Id: Auth.php,v 1.40 2002/08/25 08:15:56 markonen Exp $
//
require_once "PEAR.php";
@@ -132,7 +132,7 @@
*
* @author Martin Jansen <mj@php.net>
* @package Auth
- * @version $Revision: 1.39 $
+ * @version $Revision: 1.40 $
*/
define("AUTH_IDLED", -1);
@@ -225,6 +225,22 @@
*/
var $password = "";
+ /**
+ * Login callback function name
+ *
+ * @var string
+ * @see setLoginCallback()
+ */
+ var $loginCallback = "";
+
+ /**
+ * Logout callback function name
+ *
+ * @var string
+ * @see setLogoutCallback()
+ */
+ var $logoutCallback = "";
+
// {{{ Constructor
/**
@@ -346,6 +362,9 @@
if (!empty($this->username) && $login_ok) {
$this->setAuth($this->username);
+ if (!empty($this->loginCallback)) {
+ call_user_func($this->loginCallback,$this->username);
+ }
}
/**
@@ -416,6 +435,34 @@
$this->showLogin = $showLogin;
}
+ /**
+ * Register a callback function to be called on user login.
+ * The function will receive a single parameter, the username.
+ *
+ * @access public
+ * @param string callback function name
+ * @return void
+ * @see setLogoutCallback()
+ */
+ function setLoginCallback($loginCallback)
+ {
+ $this->loginCallback = $loginCallback;
+ }
+
+ /**
+ * Register a callback function to be called on user logout.
+ * The function will receive a single parameter, the username.
+ *
+ * @access public
+ * @param string callback function name
+ * @return void
+ * @see setLoginCallback()
+ */
+ function setLogoutCallback($logoutCallback)
+ {
+ $this->logoutCallback = $logoutCallback;
+ }
+
// }}}
// {{{ setAuthData()
@@ -633,13 +680,18 @@
* Logout function
*
* This function clears any auth tokens in the currently
- * active session
+ * active session and executes the logout callback function,
+ * if any
*
* @access public
* @return void
*/
function logout()
{
+ if (!empty($this->logoutCallback)) {
+ call_user_func($this->logoutCallback,$this->username);
+ }
+
$this->username = "";
$this->password = "";