/** * Before action. * * @param mixed $action Action. * * @return mixed */ public function beforeAction($action) { $input = file_get_contents("php://input"); if ($this->action->id != 'auth') { $token = Yii::app()->request->getParam(Api::KEY_TOKEN); if ($token && ($userId = UserApi::model()->apiGetUserId($token))) { $this->_userId = $userId; $this->_data = $input ? CJSON::decode($input) : array(); } else { $this->_response(false, Api::MESSAGE_TOKEN); Yii::app()->end(); } } return parent::beforeAction($action); }
/** * Check user. * * @param $phone * @param $password * * @return mixed */ public function apiAuth($phone, $password) { $data = null; $user = $this->findByAttributes(array('phone' => $phone, 'password' => md5($password))); if ($user && ($token = UserApi::model()->apiAdd($user->id))) { $data = array('user_id' => $user->id, 'token' => $token); } return $data; }