/** * Constructor * * @param resource$result Resultset */ public function __construct($result) { $this->db = PMF_Db::getInstance(); $arrayObject = new ArrayObject(); while ($row = $this->db->fetch_assoc($result)) { $arrayObject[] = $row; } $this->iterator = $arrayObject->getIterator(); }
/** * checks the password for the given user account. * * Returns true if the given password for the user account specified by * is correct, otherwise false. * Error messages are added to the array errors. * * @param string $login Loginname * @param string $pass Password * @param array $optionslData Optional data * @return boolean */ public function checkPassword($login, $pass, array $optionalData = null) { $check = sprintf("\n SELECT\n login, pass\n FROM\n %sfaquserlogin\n WHERE\n login = '******'", SQLPREFIX, $this->db->escape_string($login)); $check = $this->db->query($check); $error = $this->db->error(); if (strlen($error) > 0) { $this->errors[] = PMF_User::ERROR_USER_NOT_FOUND . 'error(): ' . $error; return false; } $num_rows = $this->db->num_rows($check); if ($num_rows < 1) { $this->errors[] = PMF_User::ERROR_USER_NOT_FOUND; return false; } // if login not unique, raise an error, but continue if ($num_rows > 1) { $this->errors[] = PMF_User::ERROR_USER_LOGIN_NOT_UNIQUE; } // if multiple accounts are ok, just 1 valid required while ($user = $this->db->fetch_assoc($check)) { if ($user['pass'] == $this->enc_container->encrypt($pass)) { return true; break; } } $this->errors[] = PMF_User::ERROR_USER_INCORRECT_PASSWORD; return false; }
/** * Gets the Captcha from the DB * * @return string */ public function getCaptchaCode() { $query = sprintf('SELECT id FROM %sfaqcaptcha', SQLPREFIX); $result = $this->db->query($query); while ($row = $this->db->fetch_assoc($result)) { $this->code = $row['id']; } return $this->code; }
/** * Loads the user-data from the database and returns an * associative array with the fields and values. * * @param integer $user_id User ID * @return bool */ public function load($user_id) { $user_id = (int) $user_id; if ($user_id <= 0 && $user_id != -1) { return false; } $this->user_id = $user_id; $select = sprintf("\n SELECT\n last_modified, \n display_name, \n email\n FROM\n %sfaquserdata\n WHERE\n user_id = %d", SQLPREFIX, $this->user_id); $res = $this->db->query($select); if ($this->db->num_rows($res) != 1) { return false; } $this->data = $this->db->fetch_assoc($res); return true; }
/** * Returns an array of all users found in the database. By default, the * anonymous User will not be returned. The returned array contains the * user ID as key, the values are login name, account status, authentication * source and the user creation date. * * @param boolean $withoutAnonymous Without anonymous? * @return array */ public function getAllUserData($withoutAnonymous = true) { $select = sprintf("\n SELECT\n user_id, login, account_status, auth_source, member_since\n FROM\n %sfaquser\n %s\n ORDER BY\n login ASC", SQLPREFIX, $withoutAnonymous ? 'WHERE user_id <> -1' : ''); $res = $this->db->query($select); if (!$res) { return array(); } $result = array(); while ($row = $this->db->fetch_assoc($res)) { $result[$row['user_id']] = $row; } return $result; }
/** * Returns an array with the user-IDs of all users found in * the database. By default, the Anonymous User will not be returned. * * @param boolean $withoutAnonymous Without anonymous? * @return array */ public function getAllUsers($withoutAnonymous = true) { $select = sprintf("\n SELECT\n user_id\n FROM\n %sfaquser\n %s\n ORDER BY\n login ASC", SQLPREFIX, $withoutAnonymous ? 'WHERE user_id <> -1' : ''); $res = $this->db->query($select); if (!$res) { return array(); } $result = array(); while ($row = $this->db->fetch_assoc($res)) { $result[] = $row['user_id']; } return $result; }