AssistController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * Controller is the customized base controller class.
  4. * All controller classes for this application should extend from this base class.
  5. */
  6. class AssistController extends CController
  7. {
  8. //public $layout='//layouts/iframe';
  9. public $layout = "//layouts/main";
  10. public $operateUrl; // 当前操作控制器方法
  11. // 无需登录验证白名单
  12. static $guestAcl = array(
  13. 'api/login',
  14. 'api/getTaskImg',
  15. 'api/sendTestData'
  16. );
  17. public function post($field)
  18. {
  19. return isset($_POST[$field]) ? addslashes($_POST[$field]) : null;
  20. }
  21. public function get($field)
  22. {
  23. return isset($_GET[$field]) ? addslashes($_GET[$field]) : null;
  24. }
  25. private function _getController()
  26. {
  27. return $this->controller ? $this->controller : strtolower($this->getId());
  28. }
  29. private function _getAction()
  30. {
  31. return $this->action ? $this->action : strtolower($this->getAction()->getId());
  32. }
  33. // 初始化
  34. public function init()
  35. {
  36. parent::init();
  37. $presentRequestUrl = Yii::app()->request->getPathInfo();
  38. if (isset($_GET['user_id']) && $_GET['sig']) {
  39. $UserId = safe_replace($_GET['user_id']); // 登录名
  40. $loginSig = safe_replace($_GET['sig']); // 加密值
  41. if (empty($UserId) || empty($loginSig) ) {
  42. echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
  43. exit();
  44. }
  45. // 获取助教信息
  46. $appFindUser = AssistUser::model()->findByPk($UserId)->attributes;
  47. if (empty($appFindUser)) {
  48. echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
  49. exit();
  50. }
  51. //读取session
  52. $sessionData=Yii::app()->cache->getValue($loginSig);
  53. if(!$sessionData){
  54. echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
  55. exit();
  56. }
  57. $sessionData=json_decode($sessionData,true);
  58. if($sessionData['user_id']!=$UserId){
  59. echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
  60. exit();
  61. }
  62. Yii::app()->session['user'] = $appFindUser;
  63. return true;
  64. } else {
  65. if (!isset(Yii::app()->session['user'])) {
  66. if (!in_array($presentRequestUrl, self::$guestAcl)) {
  67. echo '<script type="text/javascript">evaluationClient.sessionExpires();</script>';
  68. exit();
  69. }
  70. }
  71. }
  72. }
  73. // 相关动作执行前操作
  74. protected function beforeAction($action)
  75. {
  76. //读取基础学科
  77. $basicSubject=ASubject::model()->findAll();
  78. $subjectIdArr=array();
  79. if($basicSubject){
  80. foreach ($basicSubject as $item){
  81. $subjectIdArr[$item->subject_id]=$item->subject_name;
  82. }
  83. }
  84. if(!$subjectIdArr){
  85. Yii::app()->jump->error('无法获取科目信息');
  86. }
  87. Yii::app()->params['subjectId']=$subjectIdArr;
  88. return true;
  89. //}
  90. }
  91. public function output($code, $msg, $rs = null)
  92. {
  93. $arr = array("success" => $code, "message" => $msg);
  94. if ($rs) {
  95. $rs = Arr::pack($arr, $rs);
  96. } else {
  97. $rs = $arr;
  98. }
  99. echo json_encode($rs);
  100. exit();
  101. }
  102. /**
  103. * 生成密码
  104. * @param $password
  105. * @param string $saltOne
  106. * @param string $saltTwo
  107. * @return string
  108. */
  109. public static function producePassword($password, $saltOne = 'ywy', $saltTwo = 'zxhx')
  110. {
  111. $password = empty($password) ? '123456' : $password;
  112. return md5(sha1($password . $saltOne) . $saltTwo);
  113. }
  114. }