123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /**
- * Controller is the customized base controller class.
- * All controller classes for this application should extend from this base class.
- */
- class AssistController extends CController
- {
- //public $layout='//layouts/iframe';
- public $layout = "//layouts/main";
- public $operateUrl; // 当前操作控制器方法
- // 无需登录验证白名单
- static $guestAcl = array(
- 'api/login',
- 'api/getTaskImg',
- 'api/sendTestData'
- );
- public function post($field)
- {
- return isset($_POST[$field]) ? addslashes($_POST[$field]) : null;
- }
- public function get($field)
- {
- return isset($_GET[$field]) ? addslashes($_GET[$field]) : null;
- }
- private function _getController()
- {
- return $this->controller ? $this->controller : strtolower($this->getId());
- }
- private function _getAction()
- {
- return $this->action ? $this->action : strtolower($this->getAction()->getId());
- }
- // 初始化
- public function init()
- {
- parent::init();
- $presentRequestUrl = Yii::app()->request->getPathInfo();
- if (isset($_GET['user_id']) && $_GET['sig']) {
- $UserId = safe_replace($_GET['user_id']); // 登录名
- $loginSig = safe_replace($_GET['sig']); // 加密值
- if (empty($UserId) || empty($loginSig) ) {
- echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
- exit();
- }
- // 获取助教信息
- $appFindUser = AssistUser::model()->findByPk($UserId)->attributes;
- if (empty($appFindUser)) {
- echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
- exit();
- }
- //读取session
- $sessionData=Yii::app()->cache->getValue($loginSig);
- if(!$sessionData){
- echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
- exit();
- }
- $sessionData=json_decode($sessionData,true);
- if($sessionData['user_id']!=$UserId){
- echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
- exit();
- }
- Yii::app()->session['user'] = $appFindUser;
- return true;
- } else {
- if (!isset(Yii::app()->session['user'])) {
- if (!in_array($presentRequestUrl, self::$guestAcl)) {
- echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
- exit();
- }
- }
- }
- }
- // 相关动作执行前操作
- protected function beforeAction($action)
- {
- //读取基础学科
- $basicSubject=ASubject::model()->findAll();
- $subjectIdArr=array();
- if($basicSubject){
- foreach ($basicSubject as $item){
- $subjectIdArr[$item->subject_id]=$item->subject_name;
- }
- }
- if(!$subjectIdArr){
- Yii::app()->jump->error('无法获取科目信息');
- }
- Yii::app()->params['subjectId']=$subjectIdArr;
- return true;
- //}
- }
- public function output($code, $msg, $rs = null)
- {
- $arr = array("success" => $code, "message" => $msg);
- if ($rs) {
- $rs = Arr::pack($arr, $rs);
- } else {
- $rs = $arr;
- }
- echo json_encode($rs);
- exit();
- }
- /**
- * 生成密码
- * @param $password
- * @param string $saltOne
- * @param string $saltTwo
- * @return string
- */
- public static function producePassword($password, $saltOne = 'ywy', $saltTwo = 'zxhx')
- {
- $password = empty($password) ? '123456' : $password;
- return md5(sha1($password . $saltOne) . $saltTwo);
- }
- }
|