protected function authenticate() { // check if an api key has been specified if (!isset($_SERVER['HTTP_API_KEY'])) { $this->_sendResponse(500, 'Error: Parameter <b>API key</b> is missing'); Yii::app()->end(); } // grab api key in headers $api_key = $_SERVER['HTTP_API_KEY']; // verify api key against database $key_exists = ApiAuth::model()->find('valid_key=:api_key', array(':api_key' => $api_key)); if (count($key_exists) <= 0) { // key does not exist $this->_sendResponse(401, 'Invalid API Key!'); Yii::app()->end(); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ApiAuth the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ApiAuth::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }