| version 1.13, 2007/09/22 05:35:57 |
version 1.14, 2007/09/22 06:05:38 |
|
|
| * http://platon.sk/projects/phpPlatonLib/ |
* http://platon.sk/projects/phpPlatonLib/ |
| */ |
*/ |
| |
|
| /* $Platon: phpPlatonLib/Auth_AuthDB/AuthDB.php,v 1.12 2007-02-24 22:57:41 nepto Exp $ */ |
/* $Platon: phpPlatonLib/Auth_AuthDB/AuthDB.php,v 1.13 2007-09-22 05:35:57 nepto Exp $ */ |
| |
|
| /* |
/* |
| * History: |
* History: |
|
|
| require_once 'DB.php'; |
require_once 'DB.php'; |
| |
|
| define('AUTH_DB_COOKIE_NAME', 'AuthDB_session_id_cookie'); |
define('AUTH_DB_COOKIE_NAME', 'AuthDB_session_id_cookie'); |
| |
define('AUTH_DB_VAR_USERNAME', 'username'); |
| |
define('AUTH_DB_VAR_PASSWORD', 'password'); |
| define('AUTH_DB_UNDEFINED', 0); |
define('AUTH_DB_UNDEFINED', 0); |
| define('AUTH_DB_NOT_LOGGED', -1); |
define('AUTH_DB_NOT_LOGGED', -1); |
| define('AUTH_DB_LOGGED_IN', 1); |
define('AUTH_DB_LOGGED_IN', 1); |
|
|
| function AuthDB($options) |
function AuthDB($options) |
| { |
{ |
| $this->_options = $options; |
$this->_options = $options; |
| |
$this->_checkOptions(); |
| |
} |
| |
|
| |
function _checkOptions() |
| |
{ |
| |
if (! isset($this->_options['var']['username'])) { |
| |
$this->_options['var']['username'] = AUTH_DB_VAR_USERNAME; |
| |
} |
| |
if (! isset($this->_options['var']['password'])) { |
| |
$this->_options['var']['password'] = AUTH_DB_VAR_PASSWORD; |
| |
} |
| |
if (! isset($this->_options['cookie']['name'])) { |
| |
$this->_options['cookie']['name'] = AUTH_DB_COOKIE_NAME; |
| |
} |
| } |
} |
| |
|
| /** |
/** |
|
|
| |
|
| function assignData() |
function assignData() |
| { |
{ |
| $username_var = trim($this->_options['username_var']); |
$username_var = $this->_options['var']['username']; |
| $password_var = trim($this->_options['password_var']); |
$password_var = $this->_options['var']['password']; |
| |
|
| if (strlen($username_var) <= 0) { |
|
| $username_var = 'username'; |
|
| } |
|
| if (strlen($password_var) <= 0) { |
|
| $password_var = 'password'; |
|
| } |
|
| |
|
| /* Empty passwords are allowed. Empty usernames not. */ |
/* Empty passwords are allowed. Empty usernames not. */ |
| |
|
|
|
| || $status == AUTH_DB_FAILED |
|| $status == AUTH_DB_FAILED |
| || $status == AUTH_DB_LOGGED_IN)) { |
|| $status == AUTH_DB_LOGGED_IN)) { |
| if ($status != AUTH_DB_LOGGED_IN) { |
if ($status != AUTH_DB_LOGGED_IN) { |
| setcookie(AUTH_DB_COOKIE_NAME, '', time() - 100000); |
setcookie($this->_options['cookie']['name'], |
| |
'', /* empty string */ |
| |
time() - 100000, /* time in the past */ |
| |
$this->_options['cookie']['path'], |
| |
$this->_options['cookie']['domain']); |
| } |
} |
| return $status; |
return $status; |
| } |
} |
|
|
| |
|
| if ($status == AUTH_DB_LOGGED_IN) { |
if ($status == AUTH_DB_LOGGED_IN) { |
| $this->_DBinsert(); |
$this->_DBinsert(); |
| setcookie(AUTH_DB_COOKIE_NAME, |
setcookie($this->_options['cookie']['name'], |
| $this->_getProperty('session_id'), 0, '', '', false); |
$this->_getProperty('session_id'), |
| |
0, /* expires at the end of session */ |
| |
$this->_options['cookie']['path'], |
| |
$this->_options['cookie']['domain']); |
| } elseif ($status == AUTH_DB_FAILED) { |
} elseif ($status == AUTH_DB_FAILED) { |
| $this->_DBlog(); |
$this->_DBlog(); |
| } |
} |
|
|
| $this->_DBlogout(); |
$this->_DBlogout(); |
| $this->_status = AUTH_DB_LOGGED_OUT; |
$this->_status = AUTH_DB_LOGGED_OUT; |
| } |
} |
| setcookie(AUTH_DB_COOKIE_NAME, '', time() - 100000); |
setcookie($this->_options['cookie']['name'], |
| |
'', /* empty string */ |
| |
time() - 100000, /* time in the past */ |
| |
$this->_options['cookie']['path'], |
| |
$this->_options['cookie']['domain']); |
| } |
} |
| |
|
| function getUsername() |
function getUsername() |
|
|
| |
|
| default: |
default: |
| case 'session_id': |
case 'session_id': |
| if (isset($_COOKIE[AUTH_DB_COOKIE_NAME])) { |
if (isset($_COOKIE[$this->_options['cookie']['name']])) { |
| $ret = $_COOKIE[AUTH_DB_COOKIE_NAME]; |
$ret = $_COOKIE[$this->_options['cookie']['name']]; |
| $ret = intval(stripslashes($ret)); |
$ret = intval(stripslashes($ret)); |
| } else { |
} else { |
| $ret = ''; |
$ret = ''; |