public function authenticateToken($username, $token, $path) { // first check if username, password or path are missing if (!$username) { throw new Exception('Username not given.'); } else { if (!$token) { throw new Exception('Token not given.'); } else { if (!$path) { throw new Exception('Path not given.'); } } } $tokenResource = new Auth_Model_Resource_Token(); $tokenResource->cleanup(); $result = $tokenResource->check($username, $token, $path); if ($result === true) { $userResource = new Auth_Model_Resource_User(); $user = $userResource->fetchRow(array('where' => array('username = ?' => $username))); // store user table row in auth object, but suppress password $row = new stdClass(); $row->id = $user['id']; $row->username = $username; $row->email = $user['email']; $row->status_id = $user['status_id']; $row->role_id = $user['role_id']; // get ip and user agent $row->ip = $this->getRemoteAddr(); $row->userAgent = $this->getUserAgent(); // get role and status $row->status = $this->getStatus($row->status_id); $row->role = $this->getRole($row->role_id); // get the auth singleton and its storage and store the row $storage = Zend_Auth::getInstance()->getStorage(); $storage->write($row); return true; } else { return false; } }
/** * Fetches one row specified by its primary key from the jobs table. * @param array $sqloptions * @return array $row */ public function fetchRow($id) { // get adapter config $config = $this->getAdapter()->getConfig(); // get the sql select object for the running jobs $selectPending = $this->select(); $selectPending->from('qqueue_jobs', Query_Model_Resource_QQueueQuery::$_cols); $selectPending->where('qqueue_jobs.mysqlUserName = ?', $config['username']); $selectPending->where('qqueue_jobs.id = ?', $id); // get the sql select object for the old jobs $selectHistory = $this->select(); $selectHistory->from('qqueue_history', Query_Model_Resource_QQueueQuery::$_cols); $selectHistory->where('qqueue_history.mysqlUserName = ?', $config['username']); $selectHistory->where('qqueue_history.id = ?', $id); $select = $this->select()->union(array($selectPending, $selectHistory)); // get the rowset and return $row = $this->fetchOne($select); if (empty($row)) { return false; } // get all usernames, status, queues $userResource = new Auth_Model_Resource_User(); $statusStrings = array_flip(Query_Model_Resource_QQueueQuery::$_status); $queues = $this->fetchQueues(); // get username from cache $userRow = $userResource->fetchRow($row['user_id']); if (empty($userRow)) { $row['username'] = '******'; } else { $row['username'] = $userRow['username']; } // get status from status string array $row['status'] = $statusStrings[$row['status_id']]; // get queue $row['queue'] = $queues[$row['queue']]['name']; // calculate queue and query times if ($row['timeSubmit'] != '0000-00-00 00:00:00' && $row['timeExecute'] != '0000-00-00 00:00:00') { $row['timeQueue'] = strtotime($row['timeExecute']) - strtotime($row['timeSubmit']); } if ($row['timeExecute'] != '0000-00-00 00:00:00' && $row['timeFinish'] != '0000-00-00 00:00:00') { $row['timeQuery'] = strtotime($row['timeFinish']) - strtotime($row['timeExecute']); } // if row contains a call to spider_bg_direct_sql, the actual query run on the // server will be hidden from the user, since spider_bg_direct_sql needs secret // information that nobody should know... if (isset($row['actualQuery']) && strpos($row['actualQuery'], "spider_bg_direct_sql") !== false) { unset($row['actualQuery']); } return $row; }