Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for phpPlatonLib/Auth_AuthDB/AuthDB.php between version 1.15 and 1.16

version 1.15, 2007/09/22 06:09:11 version 1.16, 2007/09/22 06:13:06
Line 17 
Line 17 
  * 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:
Line 64  class AuthDB
Line 64  class AuthDB
                         '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;
Line 81  class AuthDB
Line 81  class AuthDB
                 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
Line 91  class AuthDB
Line 91  class AuthDB
          *                                              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'];
Line 111  class AuthDB
Line 110  class AuthDB
                                 $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;
Line 127  class AuthDB
Line 126  class AuthDB
                 $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);
Line 173  class AuthDB
Line 172  class AuthDB
                 }                  }
   
                 return $status;                  return $status;
         }          } /* }}} */
   
         function login()          function login() /* {{{ */
         {          {
                 $status = AUTH_DB_UNDEFINED;                  $status = AUTH_DB_UNDEFINED;
   
Line 196  class AuthDB
Line 195  class AuthDB
                 }                  }
   
                 return $status;                  return $status;
         }          } /* }}} */
   
         function logout()          function logout() /* {{{ */
         {          {
                 if ($this->getAuth()) {                  if ($this->getAuth()) {
                         $this->_DBlogout();                          $this->_DBlogout();
Line 209  class AuthDB
Line 208  class AuthDB
                                 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();
Line 224  class AuthDB
Line 223  class AuthDB
                 }                  }
   
                 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];
Line 281  class AuthDB
Line 280  class AuthDB
   
                 $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'],
Line 295  class AuthDB
Line 294  class AuthDB
                         $this->_error($password);                          $this->_error($password);
   
                 return $password;                  return $password;
         }          } /* }}} */
   
         function _DBinsert()          function _DBinsert() /* {{{ */
         {          {
                 mt_srand((double) microtime() * 1000000);                  mt_srand((double) microtime() * 1000000);
   
Line 326  class AuthDB
Line 325  class AuthDB
   
                 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,'
Line 343  class AuthDB
Line 342  class AuthDB
                                 $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']);
Line 370  class AuthDB
Line 369  class AuthDB
                                         $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() '
Line 387  class AuthDB
Line 386  class AuthDB
                                 $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()'
Line 405  class AuthDB
Line 404  class AuthDB
   
                 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;
Line 431  class AuthDB
Line 430  class AuthDB
                 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"'
Line 448  class AuthDB
Line 447  class AuthDB
   
                 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();
Line 520  class AuthDB
Line 519  class AuthDB
   
                 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:
    * }}} */
   
 ?>  ?>

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top