private function initLoginUserInfo() { $userId = session('user_id'); if (!empty($userId)) { $field = array('user_id', 'nick'); $this->userInfo = UserModel::instance()->getUserByUid($userId, $field); } if (empty($userId) && $this->isNeedLogin) { redirect(U('Home/User/login'), 1, 'Please Login First!'); } }
public function ranklist() { $page = I('get.page', 1, 'intval'); $pageSize = 50; if ($page < 1) { $page = 1; } $userId = I('get.userId', ''); $unick = I('get.nick', ''); $query = array(); if (!empty($userId)) { $query['user_id'] = array('like', '%' . $userId . '%'); } if (!empty($unick)) { $query['nick'] = array('like', '%' . $unick . '%'); } $query['limit'] = $pageSize; $query['page'] = $page; $query['order'] = array('solved' => 'desc', 'submit'); $field = array('user_id', 'nick', 'solved', 'submit'); $users = UserModel::instance()->getUserByQuery($query, $field); $this->assign('ranklists', $users); $this->auto_display(); }
public function doModify() { if (empty($this->userInfo)) { redirect(U('login'), 1, '请先登录账号!'); } else { $userId = session('user_id'); $unick = I('post.nick', $userId); $password = I('post.password', ''); $npassword = I('post.npassword', ''); $rptPassword = I('post.rptpassword', ''); $school = I('post.school', ''); $email = I('post.email', ''); $res = UserModel::instance()->isRightPassword($userId, $password); if ($res['code'] != 1001) { resultReturn($res['code'], array('msg' => $res['msg'])); } else { if (strlen($npassword) != 0) { $password = $npassword; } else { $rptPassword = $password; } $this->filterParam($userId, $unick, $password, $rptPassword, $school, $email); $password = UserModel::instance()->generatePassword($password); $where = array('user_id' => $userId); $option = array('nick' => $unick, 'school' => $school, 'email' => $email, 'password' => $password); UserModel::instance()->updateUserInfo($where, $option); $this->success('个人信息修改成功~', U('modify'), 2); } } }
public function register() { $data = ["name" => "123", "password" => "456"]; UserModel::instance()->register($data); $this->display(); }
public function plist() { $page = I('get.page', 0, 'intval'); $title = I('get.title', ''); $source = I('get.source', ''); if (empty($this->userInfo)) { $isAdministrator = false; $userId = ''; } else { $userId = $this->userInfo['user_id']; $isAdministrator = PrivilegeModel::instance()->isAdministrator($userId); if ($page == 0) { $_res = UserModel::instance()->getUserByUid($userId, array('volume')); $page = $_res['volume']; } else { $where = array('user_id' => $this->userInfo['user_id']); $option = array('volume' => $page); UserModel::instance()->updateUserInfo($where, $option); } } $offset = 1000; $pageSize = 100; $page = $page > 0 ? $page : 1; $offsetStart = $offset + ($page - 1) * $pageSize; $offsetEnd = $offsetStart + $pageSize; if (!empty($title)) { $query['title'] = array('like', '%' . $title . '%'); } else { if (!empty($source)) { $query['source'] = array('like', '%' . $source . '%'); } else { $query = array('problem_id' => array(array('egt', $offsetStart), array('lt', $offsetEnd)), 'order' => array('problem_id')); } } $field = array('problem_id', 'title', 'defunct', 'submit', 'accepted', 'in_date', 'author'); $problems = ProblemModel::instance()->getProblemByQuery($query, $field); if ($isAdministrator === false) { $contests = ContestModel::instance()->getNotEndedContests(array('contest_id')); $contestIds = array(); foreach ($contests as $_contest) { $contestIds[] = $_contest['contest_id']; } $contestProblemIds = ContestModel::instance()->getProblemIdsInContests($contestIds); $isInContest = array(); foreach ($contestProblemIds as $cpId) { $isInContest[$cpId] = true; } unset($contestProblemIds); } if (!empty($userId)) { // 找到该userId对应的该页提交的记录 $isSubmit = array(); $where = array('problem_id' => array(array('egt', $offsetStart), array('lt', $offsetEnd)), 'user_id' => $userId); $field = array('problem_id', 'result'); $solutions = SourceModel::instance()->getSolutionsByQuery($where, $field); foreach ($solutions as $solution) { $_pid = $solution['problem_id']; $_re = $solution['result']; if (!isset($isSubmit[$_pid])) { $isSubmit[$_pid] = $_re; } else { $isSubmit[$_pid] = $_re == 4 ? $_re : $isSubmit[$_pid]; } } unset($solutions); } else { $isSubmit = array(); } foreach ($problems['data'] as $key => $_problem) { $_pid = $_problem['problem_id']; if (isset($isSubmit[$_pid])) { if ($isSubmit[$_pid] == 4) { $problems['data'][$key]['isSubmit'] = 1; } else { $problems['data'][$key]['isSubmit'] = -1; } } else { $problems['data'][$key]['isSubmit'] = 0; } if ($isAdministrator === false) { if (empty($isInContest[$_pid])) { if ($_problem['defunct'] == 'Y') { if (empty($userId) || strcmp($_problem['author'], $userId) != 0) { unset($problems['data'][$key]); continue; } } } else { unset($problems['data'][$key]); continue; } } unset($problems['data'][$key]['defunct']); unset($problems['data'][$key]['author']); } $this->auto_display(); }