Example #1
0
 protected function logincheck()
 {
     //检测是否本系统已登录,并进行相应处理
     if (\OJLoginInterface::isLogin()) {
         //OJ已登录
         if (!(session('goldbirds_islogin') && session('goldbirds_oj') == \OJLoginInterface::getLoginUser())) {
             //OJ登录后首次访问本系统,加载登录信息到session
             $personDB = M('Person');
             $condition['ojaccount'] = \OJLoginInterface::getLoginUser();
             $user = $personDB->where($condition)->find();
             //查询关联该OJ的用户信息
             if ($user) {
                 session('goldbirds_islogin', 1);
                 session('goldbirds_uid', $user['uid']);
                 session('goldbirds_group', $user['group']);
                 session('goldbirds_oj', \OJLoginInterface::getLoginUser());
                 return 2;
                 //OJ登录且关联用户
             } else {
                 session('goldbirds_islogin', null);
                 session('goldbirds_uid', null);
                 session('goldbirds_group', null);
                 session('goldbirds_oj', null);
                 return 1;
                 //OJ登录但无关联用户
             }
         } else {
             return 2;
         }
     } else {
         //OJ未登录或已登出,清空本系统session
         session('goldbirds_islogin', null);
         session('goldbirds_uid', null);
         session('goldbirds_group', null);
         session('goldbirds_oj', null);
         return 0;
     }
 }
 public function ajax_save_regdata()
 {
     //提交注册信息
     if ($this->logincheck() == 0) {
         $this->myajaxReturn(null, '[错误]请先登录OJ。', 5);
     }
     //未登录,非法操作
     $aid = I('post.aid');
     if ($aid <= 0) {
         $this->myajaxReturn(null, '[错误]无效的AID参数。', 1);
     }
     $activitylistDB = M('Activitylist');
     $activity = $activitylistDB->where('aid = ' . $aid)->find();
     //合法性检查
     if (!$activity) {
         $this->myajaxReturn(null, '[错误]无效的AID参数。', 1);
     }
     if ($activity['isinner'] == 1 && $this->logincheck() != 2) {
         $this->myajaxReturn(null, '[错误]没有权限。', 6);
     }
     //内部活动,非法操作
     if (time() > strtotime($activity['deadline'])) {
         $this->myajaxReturn(null, '[错误]报名时间已截止。', 2);
     }
     //时间已截止
     $activitydataDB = M('Activitydata');
     $regdata = $activitydataDB->where('aid = ' . $aid . ' AND ojaccount = "' . \OJLoginInterface::getLoginUser() . '"')->find();
     if (!$regdata) {
         //注册
         $postdata = I('post.regdata', false, '');
         //传进的是数组
         $datastr = '';
         if (count($postdata) < 1) {
             $this->myajaxReturn(null, '[错误]无效的请求数据。', 3);
         }
         //调用自定义类进行输入数据合法性校验
         $rule = $this->explain_reg_rule($activity['form']);
         if ($rule === null) {
             $this->myajaxReturn(null, '[错误]系统错误,无效的活动规则字符串。', 9);
         }
         if ($rule[0]['classname'] != null) {
             Vendor('ActivityFormClass.activity');
             $checkres = null;
             if (!class_exists($rule[0]['classname']) || !method_exists($rule[0]['classname'], 'checkdata') || false === eval('$checkres = ' . $rule[0]['classname'] . '::checkdata($postdata);') || !is_string($checkres) && !is_array($checkres)) {
                 $this->myajaxReturn(null, '[错误]系统错误,无效的自定义活动类。', 7);
             }
             //自定义类不合法
             if (is_string($checkres)) {
                 $this->myajaxReturn(null, $checkres, 8);
             } else {
                 $postdata = $checkres;
             }
         }
         for ($i = 0; $i < count($postdata); $i++) {
             if ($i == 0) {
                 $datastr .= base64_encode($postdata[$i]);
             } else {
                 $datastr = $datastr . ',' . base64_encode($postdata[$i]);
             }
         }
         $d['aid'] = $aid;
         $d['ojaccount'] = \OJLoginInterface::getLoginUser();
         $d['data'] = $datastr;
         if ($activity['isneedreview'] == 1) {
             $d['state'] = 0;
         } else {
             $d['state'] = 2;
         }
         $d['regtime'] = date('Y-m-d H:i:s', time());
         if ($activitydataDB->add($d)) {
             $this->myajaxReturn(null, '[成功]报名活动成功!', 0);
         } else {
             $this->myajaxReturn(null, '[错误]报名活动失败!', 4);
         }
     } else {
         //修改
         if ($activity['isneedreview'] == 1 && $regdata['state'] == 2) {
             $this->myajaxReturn(null, '[错误]你已通过审核,无法修改报名信息。如果确实需要修改,请联系管理员。', 7);
         }
         $adid = $regdata['adid'];
         $postdata = I('post.regdata', false, '');
         //传进的是数组
         $datastr = '';
         if (count($postdata) < 1) {
             $this->myajaxReturn(null, '[错误]无效的请求数据。', 3);
         }
         //调用自定义类进行输入数据合法性校验
         $rule = $this->explain_reg_rule($activity['form']);
         if ($rule === null) {
             $this->myajaxReturn(null, '[错误]系统错误,无效的活动规则字符串。', 9);
         }
         if ($rule[0]['classname'] != null) {
             Vendor('ActivityFormClass.activity');
             $checkres = null;
             if (!class_exists($rule[0]['classname']) || !method_exists($rule[0]['classname'], 'checkdata') || false === eval('$checkres = ' . $rule[0]['classname'] . '::checkdata($postdata);') || !is_string($checkres) && !is_array($checkres)) {
                 $this->myajaxReturn(null, '[错误]系统错误,无效的自定义活动类。', 7);
             }
             //自定义类不合法
             if (is_string($checkres)) {
                 $this->myajaxReturn(null, $checkres, 8);
             } else {
                 $postdata = $checkres;
             }
         }
         for ($i = 0; $i < count($postdata); $i++) {
             if ($i == 0) {
                 $datastr .= base64_encode($postdata[$i]);
             } else {
                 $datastr = $datastr . ',' . base64_encode($postdata[$i]);
             }
         }
         $d['data'] = $datastr;
         if ($activity['isneedreview'] == 1) {
             $d['state'] = 0;
         } else {
             $d['state'] = 2;
         }
         $result = $activitydataDB->where('adid = ' . $adid . ' AND ojaccount = "' . \OJLoginInterface::getLoginUser() . '"')->save($d);
         if ($result !== false) {
             $this->myajaxReturn(null, '[成功]修改活动报名信息成功!', 0);
         } else {
             $this->myajaxReturn(null, '[错误]修改活动报名信息失败!', 4);
         }
     }
 }
Example #3
0
 public function ajax_replytalk()
 {
     //回复talk
     if ($this->logincheck() == 0) {
         $this->myajaxReturn(null, '[错误]你还未登录。', 1);
     } else {
         //已登录
         $verify = new \Think\Verify();
         if (!$verify->check(I('post.verify', '', false))) {
             $this->myajaxReturn(null, '[错误]验证码错误。', 1);
         }
         $title = I('post.title', '', false);
         if (strlen($title) < TalkController::$var_title_minlen) {
             $this->myajaxReturn(null, '[错误]标题长度不能小于' . TalkController::$var_title_minlen . '。', 2);
         }
         if (strlen($title) > TalkController::$var_title_maxlen) {
             $this->myajaxReturn(null, '[错误]标题长度不能大于' . TalkController::$var_title_maxlen . '。', 2);
         }
         $content = I('post.content', '', false);
         if (strlen($content) > TalkController::$var_content_maxlen) {
             $this->myajaxReturn(null, '[错误]内容太长了-_-', 2);
         }
         if (strlen($content) == 0) {
             $content = null;
         }
         $tid = intval(I('post.tid', '', false));
         if ($this->addson($tid, $title, \OJLoginInterface::getLoginUser(), $content)) {
             $this->myajaxReturn(null, '[成功]', 0);
         } else {
             $this->myajaxReturn(null, '[错误]回复失败。', 3);
         }
     }
 }
 public function ajax_bind_luckycode()
 {
     //验证邀请码
     if ($this->logincheck() == 0) {
         $this->myajaxReturn(null, '[错误]还未登录,无权限。', 2);
     }
     //无权限处理
     $code = I('post.code');
     $email = I('post.email', '', false);
     $phone = I('post.phone', '', false);
     $oj = \OJLoginInterface::getLoginUser();
     sleep(1);
     if (strlen($code) != 16) {
         $this->myajaxReturn(null, '[错误]无效的邀请码,请重试!', 1);
     } else {
         if (!preg_match('/^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,5}$/', $email)) {
             $this->myajaxReturn(null, '[错误]E-mail格式不正确!请重试。', 1);
         } else {
             if (strlen($phone) < 8 || strlen($phone) > 11) {
                 $this->myajaxReturn(null, '[错误]联系电话格式不正确!请重试。', 1);
             } else {
                 $personDB = M('Person');
                 $c['luckycode'] = $code;
                 $data = $personDB->field('uid, chsname, engname, ojaccount')->where($c)->find();
                 if ($data) {
                     if ($data['ojaccount'] == null) {
                         //验证完毕,准备绑定
                         $data['ojaccount'] = $oj;
                         $data['phone'] = $phone;
                         $data['email'] = $email;
                         if ($personDB->where('uid = ' . $data['uid'])->limit(1)->save($data)) {
                             $this->myajaxReturn(null, '[成功]', 0);
                         } else {
                             $this->myajaxReturn(null, '[错误]绑定失败,请刷新后重试。', 0);
                         }
                     } else {
                         $this->myajaxReturn(null, '[错误]无效的邀请码,请重试!', 1);
                     }
                 } else {
                     $this->myajaxReturn(null, '[错误]无效的邀请码,请重试!', 1);
                 }
             }
         }
     }
 }