コード例 #1
0
ファイル: MDB2.php プロジェクト: BackupTheBerlios/hem
 /**
  * LiveUser_Auth_Container_MDB2::readUserData()
  *
  * Reads auth_user_id, passwd, is_active flag
  * lastlogin timestamp from the database
  * If only $handle is given, it will read the data
  * from the first user with that handle and return
  * true on success.
  * If $handle and $passwd are given, it will try to
  * find the first user with both handle and password
  * matching and return true on success (this allows
  * multiple users having the same handle but different
  * passwords - yep, some people want this).
  * If no match is found, false is being returned.
  *
  * @param string $handle
  * @param boolean $passwd
  * @return boolean
  */
 function readUserData($handle, $passwd = false)
 {
     if (!$this->init_ok) {
         return false;
     }
     $success = false;
     $fields = array();
     foreach ($this->authTableCols as $key => $value) {
         $fields[] = $value['name'] . ' AS ' . $key;
         $types[] = $value['type'];
     }
     if ($passwd !== false) {
         // If $passwd is set, try to find the first user with the given
         // handle and password.
         $sql = 'SELECT ' . implode(',', $fields) . '
                    FROM ' . $this->authTable . '
                    WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->quote($handle, $this->authTableCols['handle']['type']) . '
                     AND ' . $this->authTableCols['passwd']['name'] . '=' . $this->dbc->quote($this->encryptPW($passwd), $this->authTableCols['passwd']['type']);
     } else {
         // If only $handle is set, try to find the first matching user
         $sql = 'SELECT ' . implode(',', $fields) . '
                    FROM  ' . $this->authTable . '
                    WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->quote($handle, $this->authTableCols['handle']['type']);
     }
     // Query database
     $result = $this->dbc->queryRow($sql, $types, MDB2_FETCHMODE_ASSOC);
     // If a user was found, read data into class variables and set
     // return value to true
     if (!MDB2::isError($result) && is_array($result)) {
         $this->handle = $result['handle'];
         $this->passwd = $this->decryptPW($result['passwd']);
         $this->isActive = !isset($result['is_active']) || $result['is_active'] ? true : false;
         $this->authUserId = $result['user_id'];
         $this->lastLogin = !empty($result['lastlogin']) ? MDB2_Date::mdbstamp2Unix($result['lastlogin']) : '';
         $success = true;
     }
     return $success;
 }
コード例 #2
0
ファイル: MDB2.php プロジェクト: Zunair/xataface
 /**
  * Reads auth_user_id, passwd, is_active flag
  * lastlogin timestamp from the database
  * If only $handle is given, it will read the data
  * from the first user with that handle and return
  * true on success.
  * If $handle and $passwd are given, it will try to
  * find the first user with both handle and password
  * matching and return true on success (this allows
  * multiple users having the same handle but different
  * passwords - yep, some people want this).
  * If no match is found, false is being returned.
  *
  * @param  string $handle  user handle
  * @param  boolean $passwd user password
  * @param string $auth_user_id auth user id
  * @return boolean true on success or false on failure
  *
  * @access private
  */
 function readUserData($handle = '', $passwd = '', $auth_user_id = false)
 {
     $fields = $types = array();
     foreach ($this->tables['users']['fields'] as $field => $req) {
         $fields[] = $this->alias[$field] . ' AS ' . $field;
         $types[] = $this->fields[$field];
     }
     // Setting the default query.
     $query = 'SELECT ' . implode(',', $fields) . '
                FROM ' . $this->prefix . $this->alias['users'] . '
                WHERE  ';
     if ($auth_user_id) {
         $query .= $this->alias['auth_user_id'] . '=' . $this->dbc->quote($this->propertyValues['auth_user_id'], $this->fields['auth_user_id']);
     } else {
         $query .= $this->alias['handle'] . '=' . $this->dbc->quote($handle, $this->fields['handle']);
         if ($this->tables['users']['fields']['passwd']) {
             // If $passwd is set, try to find the first user with the given
             // handle and password.
             $query .= ' AND   ' . $this->alias['passwd'] . '=' . $this->dbc->quote($this->encryptPW($passwd), $this->fields['passwd']);
         }
     }
     // Query database
     $result = $this->dbc->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
     // If a user was found, read data into class variables and set
     // return value to true
     if (PEAR::isError($result)) {
         $this->_stack->push(LIVEUSER_ERROR, 'exception', array('reason' => $result->getMessage() . '-' . $result->getUserInfo()));
         return false;
     }
     if (!is_array($result)) {
         return null;
     }
     if (array_key_exists('lastlogin', $result) && !empty($result['lastlogin'])) {
         $result['lastlogin'] = MDB2_Date::mdbstamp2Unix($result['lastlogin']);
     }
     $this->propertyValues = $result;
     return true;
 }