| version 1.15, 2007/09/22 06:09:11 |
version 1.16, 2007/09/22 06:13:06 |
|
|
| * http://platon.sk/projects/phpPlatonLib/ |
* http://platon.sk/projects/phpPlatonLib/ |
| */ |
*/ |
| |
|
| /* $Platon: phpPlatonLib/Auth_AuthDB/AuthDB.php,v 1.14 2007-09-22 06:05:38 nepto Exp $ */ |
/* $Platon: phpPlatonLib/Auth_AuthDB/AuthDB.php,v 1.15 2007-09-22 06:09:11 nepto Exp $ */ |
| |
|
| /* |
/* |
| * History: |
* History: |
|
|
| 'remote_ip' => null |
'remote_ip' => null |
| ); |
); |
| |
|
| function AuthDB($options) |
function AuthDB($options) /* {{{ */ |
| { |
{ |
| $this->_options = $options; |
$this->_options = $options; |
| $this->_checkOptions(); |
$this->_checkOptions(); |
| } |
} /* }}} */ |
| |
|
| function _checkOptions() |
function _checkOptions() /* {{{ */ |
| { |
{ |
| if (! isset($this->_options['var']['username'])) { |
if (! isset($this->_options['var']['username'])) { |
| $this->_options['var']['username'] = AUTH_DB_VAR_USERNAME; |
$this->_options['var']['username'] = AUTH_DB_VAR_USERNAME; |
|
|
| if (! isset($this->_options['cookie']['name'])) { |
if (! isset($this->_options['cookie']['name'])) { |
| $this->_options['cookie']['name'] = AUTH_DB_COOKIE_NAME; |
$this->_options['cookie']['name'] = AUTH_DB_COOKIE_NAME; |
| } |
} |
| } |
} /* }}} */ |
| |
|
| /** |
/** |
| * Tells AuthDB, that particular user is already authentificated |
* Tells AuthDB, that particular user is already authentificated |
|
|
| * username of already logged in user |
* username of already logged in user |
| * @return status |
* @return status |
| */ |
*/ |
| function setLoggedFunction($fncname) |
function setLoggedFunction($fncname) /* {{{ */ |
| { |
{ |
| $this->_logged_fnc = $fncname; |
$this->_logged_fnc = $fncname; |
| } |
} /* }}} */ |
| |
|
| |
function assignData() /* {{{ */ |
| function assignData() |
|
| { |
{ |
| $username_var = $this->_options['var']['username']; |
$username_var = $this->_options['var']['username']; |
| $password_var = $this->_options['var']['password']; |
$password_var = $this->_options['var']['password']; |
|
|
| $this->_props['password'] = $_POST[$password_var]; |
$this->_props['password'] = $_POST[$password_var]; |
| } |
} |
| } |
} |
| } |
} /* }}} */ |
| |
|
| /* PEAR Auth class compatibility */ |
/* PEAR Auth class compatibility */ |
| function getAuth() |
function getAuth() /* {{{ */ |
| { |
{ |
| return $this->getStatus() == AUTH_DB_LOGGED_IN; |
return $this->getStatus() == AUTH_DB_LOGGED_IN; |
| } |
} /* }}} */ |
| |
|
| function getStatus() |
function getStatus() /* {{{ */ |
| { |
{ |
| if ($this->_status != AUTH_DB_UNDEFINED) |
if ($this->_status != AUTH_DB_UNDEFINED) |
| return $this->_status; |
return $this->_status; |
|
|
| $this->_status = $this->_processStatus(); |
$this->_status = $this->_processStatus(); |
| |
|
| return $this->_status; |
return $this->_status; |
| } |
} /* }}} */ |
| |
|
| function _processStatus() |
function _processStatus() /* {{{ */ |
| { |
{ |
| if ($this->_logged_fnc != null && function_exists($this->_logged_fnc)) { |
if ($this->_logged_fnc != null && function_exists($this->_logged_fnc)) { |
| $this->_props['username'] = call_user_func($this->_logged_fnc); |
$this->_props['username'] = call_user_func($this->_logged_fnc); |
|
|
| } |
} |
| |
|
| return $status; |
return $status; |
| } |
} /* }}} */ |
| |
|
| function login() |
function login() /* {{{ */ |
| { |
{ |
| $status = AUTH_DB_UNDEFINED; |
$status = AUTH_DB_UNDEFINED; |
| |
|
|
|
| } |
} |
| |
|
| return $status; |
return $status; |
| } |
} /* }}} */ |
| |
|
| function logout() |
function logout() /* {{{ */ |
| { |
{ |
| if ($this->getAuth()) { |
if ($this->getAuth()) { |
| $this->_DBlogout(); |
$this->_DBlogout(); |
|
|
| time() - 100000, /* time in the past */ |
time() - 100000, /* time in the past */ |
| $this->_options['cookie']['path'], |
$this->_options['cookie']['path'], |
| $this->_options['cookie']['domain']); |
$this->_options['cookie']['domain']); |
| } |
} /* }}} */ |
| |
|
| function getUsername() |
function getUsername() /* {{{ */ |
| { |
{ |
| return $this->_DBgetUsername(); |
return $this->_DBgetUsername(); |
| } |
} /* }}} */ |
| |
|
| function getUserInfo() |
function getUserInfo() /* {{{ */ |
| { |
{ |
| if ($this->getAuth()) { |
if ($this->getAuth()) { |
| $this->_props['username'] = $this->getUsername(); |
$this->_props['username'] = $this->getUsername(); |
|
|
| } |
} |
| |
|
| return false; |
return false; |
| } |
} /* }}} */ |
| |
|
| |
|
| // Private methods |
// Private methods |
| |
|
| function _checkDB() |
function _checkDB() /* {{{ */ |
| { |
{ |
| if (! isset($this->_db)) { |
if (! isset($this->_db)) { |
| $this->_db = DB::connect($this->_options['dsn']); |
$this->_db = DB::connect($this->_options['dsn']); |
| DB::isError($this->_db) && $this->_error($this->_db); |
DB::isError($this->_db) && $this->_error($this->_db); |
| $this->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
$this->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
| } |
} |
| } |
} /* }}} */ |
| |
|
| function _error($error) |
function _error($error) /* {{{ */ |
| { |
{ |
| die('AuthDB error: '.$error->getMessage()); |
die('AuthDB error: '.$error->getMessage()); |
| // sensitive! |
// sensitive! |
| // $error->getDebugInfo(); |
// $error->getDebugInfo(); |
| } |
} /* }}} */ |
| |
|
| function _getProperty($property) |
function _getProperty($property) /* {{{ */ |
| { |
{ |
| if (isset($this->_props[$property])) |
if (isset($this->_props[$property])) |
| return $this->_props[$property]; |
return $this->_props[$property]; |
|
|
| |
|
| $this->_props[$property] = $ret; |
$this->_props[$property] = $ret; |
| return $ret; |
return $ret; |
| } |
} /* }}} */ |
| |
|
| function _DBgetPassword() |
function _DBgetPassword() /* {{{ */ |
| { |
{ |
| $query = sprintf('SELECT %s FROM %s WHERE %s = %s', |
$query = sprintf('SELECT %s FROM %s WHERE %s = %s', |
| $this->_options['users']['cols']['password'], |
$this->_options['users']['cols']['password'], |
|
|
| $this->_error($password); |
$this->_error($password); |
| |
|
| return $password; |
return $password; |
| } |
} /* }}} */ |
| |
|
| function _DBinsert() |
function _DBinsert() /* {{{ */ |
| { |
{ |
| mt_srand((double) microtime() * 1000000); |
mt_srand((double) microtime() * 1000000); |
| |
|
|
|
| |
|
| DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
| $this->_props['session_id'] = $session_id; |
$this->_props['session_id'] = $session_id; |
| } |
} /* }}} */ |
| |
|
| function _DBlog() |
function _DBlog() /* {{{ */ |
| { |
{ |
| $query = sprintf('INSERT INTO %s' |
$query = sprintf('INSERT INTO %s' |
| .' (status, login, logout,' |
.' (status, login, logout,' |
|
|
| $this->_db->quote($this->_getProperty('user_agent'))); |
$this->_db->quote($this->_getProperty('user_agent'))); |
| |
|
| DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
| } |
} /* }}} */ |
| |
|
| function _DBupdateTimeout() |
function _DBupdateTimeout() /* {{{ */ |
| { |
{ |
| $timeout = intval($this->_options['timeout']); |
$timeout = intval($this->_options['timeout']); |
| $expired = intval($this->_options['expired']); |
$expired = intval($this->_options['expired']); |
|
|
| $this->_db->quote($expired)); |
$this->_db->quote($expired)); |
| DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
| } |
} |
| } |
} /* }}} */ |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _DBlogout() |
function _DBlogout() /* {{{ */ |
| { |
{ |
| $query = sprintf('UPDATE %s' |
$query = sprintf('UPDATE %s' |
| .' SET status = "logout", logout = sysdate() ' |
.' SET status = "logout", logout = sysdate() ' |
|
|
| $this->_db->quote($this->_getProperty('user_agent'))); |
$this->_db->quote($this->_getProperty('user_agent'))); |
| |
|
| DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
| } |
} /* }}} */ |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _DBupdateLogin() |
function _DBupdateLogin() /* {{{ */ |
| { |
{ |
| $query = sprintf('UPDATE %s' |
$query = sprintf('UPDATE %s' |
| .' SET logout = sysdate()' |
.' SET logout = sysdate()' |
|
|
| |
|
| DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
DB::isError($res = $this->_db->query($query)) && $this->_error($res); |
| return $this->_db->affectedRows() > 0 ? true : false; |
return $this->_db->affectedRows() > 0 ? true : false; |
| } |
} /* }}} */ |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _DBcheckLogin() |
function _DBcheckLogin() /* {{{ */ |
| { |
{ |
| if ($this->_DBupdateLogin() == true) |
if ($this->_DBupdateLogin() == true) |
| return true; |
return true; |
|
|
| if (in_array('expired', $res)) return AUTH_DB_EXPIRED; |
if (in_array('expired', $res)) return AUTH_DB_EXPIRED; |
| if (in_array('online', $res)) return AUTH_DB_LOGGED_IN; |
if (in_array('online', $res)) return AUTH_DB_LOGGED_IN; |
| return AUTH_DB_UNDEFINED; |
return AUTH_DB_UNDEFINED; |
| } |
} /* }}} */ |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _DBgetUsername() |
function _DBgetUsername() /* {{{ */ |
| { |
{ |
| $query = sprintf('SELECT username FROM %s' |
$query = sprintf('SELECT username FROM %s' |
| .' WHERE status = "online"' |
.' WHERE status = "online"' |
|
|
| |
|
| DB::isError($res = $this->_db->getCol($query)) && $this->_error($res); |
DB::isError($res = $this->_db->getCol($query)) && $this->_error($res); |
| return $res[0]; |
return $res[0]; |
| } |
} /* }}} */ |
| |
|
| function _DBgetUserInfo() |
function _DBgetUserInfo() /* {{{ */ |
| { |
{ |
| $select_cols = array(); |
$select_cols = array(); |
| $select_tables = array(); |
$select_tables = array(); |
|
|
| |
|
| DB::isError($res = $this->_db->getRow($query)) && $this->_error($res); |
DB::isError($res = $this->_db->getRow($query)) && $this->_error($res); |
| return $res; |
return $res; |
| } |
} /* }}} */ |
| |
|
| } |
} |
| |
|
| |
/* Modeline for ViM {{{ |
| |
* vim: set ts=4: |
| |
* vim600: fdm=marker fdl=0 fdc=0: |
| |
* }}} */ |
| |
|
| ?> |
?> |