Esempio n. 1
0
 /**
  * 用户管理页面
  * 
  */
 public function index()
 {
     $role_id = I('role_id');
     $nickname = I('nickname');
     $type = I('type');
     $user = new UserModel();
     $data = $user->get_user_list($role_id, $nickname);
     if ('searchUserList' == $type) {
         $data = json_encode($data);
         echo $data;
         exit;
     }
     $userinfodata = $data['data'];
     $role = M('Role');
     $show = $data['show'];
     $roleList = $role->select();
     $role_select[$role_id] = " selected = 'selected' ";
     $this->assign('role_select', $role_select);
     $this->assign('userinfolist', $userinfodata);
     $this->assign('roleList', $roleList);
     $this->assign('nickname', $nickname);
     $this->assign('role_id', $role_id);
     $this->assign('page', $show);
     $this->display();
 }
Esempio n. 2
0
 public function index()
 {
     $db = new UserModel();
     //        $db = D('user');
     $select = $db->select();
     $this->assign('select', $select);
     $name = 'ThinkPHP';
     $this->assign('name', $name);
     $this->display();
 }
Esempio n. 3
0
 public function volist()
 {
     $model = new UserModel();
     $list = $model->select();
     $this->assign("list", $list);
     $this->assign("aa", 1);
     $this->assign("v", 1);
     layout(false);
     dump(APP_PATH);
     $this->display();
 }
 public function addUser($data)
 {
     $user_model = new UserModel();
     $data['password'] = $user_model->do_mencrypt($data['password'], "1234");
     $user = M("user");
     $res = $user->where(array('username' => $name))->find();
     if (empty($res)) {
         $res = $user->add($data);
         return $res;
     }
     return false;
 }
Esempio n. 5
0
 public function save()
 {
     //        //创建模型对象
     $Model = new UserModel();
     //        //调用delete方法删除数据
     $result = $Model->add($_POST);
     if ($result) {
         //            header('Location:index.php?m=Home&c=User&a=index');
         $this->success('添加成功', U('index'));
         //            $this->redirect('index');
     } else {
         echo '添加失败' . $Model->getError();
     }
 }
 public function loginCheck()
 {
     $User = new UserModel();
     $loginArray['username'] = $_POST['username'];
     $loginArray['password'] = $_POST['password'];
     $result = $User->loginCheck($loginArray);
     if ($result['status']) {
         $_SESSION['username'] = $loginArray['username'];
         $_SESSION['userid'] = $result['userid'];
         $_SESSION['userlevel'] = 0;
         $this->ajaxReturn($result);
     } else {
         $this->ajaxReturn($result);
     }
 }
Esempio n. 7
0
 public function searchfriend()
 {
     //获取推荐好友列表(除本身和好友)
     $user = new UserModel('User');
     $map = array();
     $map['id'] = array('neq', $_SESSION['user']['id']);
     $data = $user->where($map)->select();
     //检查该用户是否设置头像
     foreach ($data as $key => $value) {
         //$img = new IndexController();
         //$ishead = $img->isUploadHead($value['id']);
         $img = D('HeadImg');
         $img = $img->getUserHeadList($value['id']);
         $data[$key]['src'] = $img['head_img_middle'];
     }
     //dump($data);
     //获取好友请求
     $msg = new NoticeController();
     $condition = array('flag' => 3, 'uid' => $_SESSION['user']['id']);
     $list = $msg->getlist($condition);
     //遍历请求数组找出对应消息发送者姓名
     foreach ($list as $key => $v) {
         //获取发送者信息
         $condition['id'] = $v['sid'];
         $sender = D('user');
         $sender = $sender->getUserInfo($condition);
         $list[$key]['name'] = $sender['username'];
     }
     //获取好友列表
     $friendlist = $this->getFriendList($_SESSION['user']['id']);
     //dump($friendlist);
     //排除好友
     if (!empty($friendlist)) {
         foreach ($friendlist as $k => $v) {
             foreach ($data as $key => $value) {
                 if (in_array($v['uid'], $value)) {
                     unset($data[$key]);
                 }
             }
         }
     }
     //dump($data);
     $this->assign('msglist', $list);
     $this->assign('friendlist', $friendlist);
     $this->assign('list', $data);
     $this->assign('title', '找好友');
     $this->display();
 }
 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!');
     }
 }
Esempio n. 9
0
 public function fabuadd()
 {
     die(dump($_POST));
     $user = new UserModel();
     $condition = array('LoginName' => $_POST['LoginName']);
     $user_id = $user->getUserId($condition);
     if (is_array($user_id)) {
         foreach ($user_id as $v) {
             $user_id = $v['id'];
         }
     }
     $train = new TrainingModel();
     //        $training_name = $train->getTrainingNameById($_POST['training_id']);
     $messge = new TrainMessageModel();
     $condition = array('training_id' => $_POST['training_id'], 'user_id' => $user_id, 'message_title' => $_POST['message_title'], 'class_type' => $_POST['class_type'], 'message_jianjie' => $_POST['message_jianjie'], 'message_content' => $_POST['message_content'], 'date' => time());
     $messge_add = $messge->AddTrainMessage($condition);
     if ($messge_add) {
         echo "<script>alert('信息发布成功!!!');</script>";
     } else {
         echo "<script>alert('信息发布失败!!!');</script>";
     }
 }
 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();
 }
Esempio n. 11
0
 public function register()
 {
     $data = ["name" => "123", "password" => "456"];
     UserModel::instance()->register($data);
     $this->display();
 }
 /**
  * 获取账户下面的所有代理及用户
  * @param int 用户id
  * @return array
  */
 public function treeUser($id)
 {
     $arr = array();
     $arr = F(session('name') . '/member');
     if (empty($arr) || !$arr) {
         static $tree = array();
         $User = new UserModel();
         $data = $User->where(array('pid' => $id))->field('id,name,role_id,lasttime,lastip')->select();
         !in_array($data, $tree) ? $tree[] = $data : '';
         if ($data) {
             foreach ($data as $item) {
                 if (!is_array($item)) {
                     continue;
                 } else {
                     $this->treeUser($item['id']);
                 }
             }
         }
         $arr = array();
         foreach ($tree as $item) {
             if (!$item) {
                 continue;
             }
             foreach ($item as $v) {
                 $v['role_id'] == '3' ? $arr['user'][] = $v : ($arr['agent'][] = $v);
             }
         }
         F(session('name') . '/member', $arr);
     }
     return $arr;
 }
Esempio n. 13
0
 /**
  * 修改用户手机号新手机验证码.
  *
  * @access public
  * @return void
  * @author Liuping <*****@*****.**>
  */
 public function changeInfoPhonePhoneCode()
 {
     // 当前语系
     $lang = LANG_SET;
     $username = session('username');
     $prefix = I('mobilePrefix', '');
     $phone = I('phone', '');
     $newphone = $this->processMobile($prefix, $phone);
     // 处理后的手机号
     $model = new UserModel();
     $userInfo = $model->checkExistTel($prefix, $phone);
     if (empty($phone)) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG1');
     } elseif (!preg_match($this->_patternMobile, $newphone)) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG9');
     } elseif ($userInfo && $username != $userInfo['username']) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG10');
     } else {
         // 获取验证码
         $code = $this->getRandCode();
         $model = new UserCaptchaModel();
         $res = $model->checkSended($newphone, 1);
         if ($res) {
             // 重复发送
             $result['status'] = 8;
             $result['msg'] = '您的验证码已发送, 请不要重复发送';
             $this->ajaxReturn($result, 'json');
         }
         // 表中没有验证码, 手机验证码发送成功 commit, 失败 rollback
         $model->startTrans();
         $model->id = NULL;
         $model->type = 1;
         // 1 为手机, 2 为邮箱
         $model->account = $newphone;
         $model->code = $code;
         $model->createtime = time();
         $res1 = $model->add();
         $conf = C('USER_CAPTCHA_INFO');
         // 验证码配置项
         $timeout = $conf['expire'] / 60;
         // 短信内容
         $tpl = ['zh-cn' => 'ApplicationUK:[%CODE%] is your verification code. This code will expire in %TIMEOUT% minutes. Please do not reply to this message', 'en-us' => 'ApplicationUK:[%CODE%] is your verification code. This code will expire in %TIMEOUT% minutes. Please do not reply to this message'];
         $_searches = ['%CODE%', '%TIMEOUT%'];
         $_replaces = [$code, $timeout];
         $content = isset($tpl[$lang]) ? $tpl[$lang] : $tpl['en-us'];
         // $content = str_replace('%CODE%', $code, $content);
         $content = str_replace($_searches, $_replaces, $content);
         $res = $this->sendSms($newphone, $content);
         $result = [];
         // 成功发送将验证码信息写入 user_captcha
         if ($res && $res1) {
             $model->commit();
             $result['status'] = 9;
             $result['msg'] = L('CONTROLLER_MSG100');
         } else {
             $model->rollback();
             $result['status'] = 8;
             $result['msg'] = L('CONTROLLER_MSG24');
         }
     }
     if (IS_AJAX) {
         $this->ajaxReturn($result, 'json');
     }
 }
 /**
  * 微信客服回复函数
  */
 private function wxServiceRepeat($UserId, $msg)
 {
     $wxChat = new JSSDKModel();
     $Token = $wxChat->GetToken();
     $UserModel = new UserModel();
     $UserResult = $UserModel->GetUserInfo($UserId);
     $data['touser'] = $UserResult['openid'];
     $data['msgtype'] = 'text';
     $data['text'] = array('content' => $msg);
     $data = $this->encode_json($data);
     $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $Token;
     $header = array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data));
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // The maximum number of seconds to allow cURL functions to execute.
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
     $response = curl_exec($ch);
     if (curl_errno($ch)) {
         return false;
         //return curl_errno($ch);
     }
     curl_close($ch);
     if (!isset($response['errcode'])) {
         return true;
     } else {
         return false;
     }
 }
 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();
 }
Esempio n. 16
0
 public function edit()
 {
     //获取当前用户ID
     $user = new UserModel('user');
     $rs = $user->where(array('email' => $email))->find();
     $id = $rs['id'];
     $_POST['uid'] = $id;
     //创建默认相册
     $albumcol = new AlbumController();
     $aid = $albumcol->createAlbum();
     $_POST['aid'] = $aid;
     //完善其他资料
     $email = $_SESSION['email'];
     $user = M('user');
     if (!$user->create()) {
         $this->error($user->getError());
     }
     if ($user->where(array('email' => $email))->save()) {
         $this->success('成功完善', U('Index/index'));
     }
     //echo $user->getLastsql();
 }
 public function modify()
 {
     $this->checkLogin();
     $User = new UserModel();
     $user['US_id'] = session('userid');
     if (strlen($_POST['US_name']) != 0) {
         $user['US_name'] = $_POST['US_name'];
     }
     if (strlen($_POST['US_sex']) != 0) {
         $user['US_sex'] = $_POST['US_sex'];
     }
     if (strlen($_POST['US_birth']) != 0) {
         $user['US_birth'] = $_POST['US_birth'];
     }
     if (strlen($_POST['US_face']) != 0) {
         $user['US_face'] = $_POST['US_face'];
     }
     if (strlen($_POST['US_highest']) != 0) {
         $user['US_highest'] = $_POST['US_highest'];
     }
     if (strlen($_POST['US_major']) != 0) {
         $user['US_major'] = $_POST['US_major'];
     }
     if (strlen($_FILES['US_image']['name'][0]) == 0) {
         $status = $User->modifyUser($user);
         if ($status) {
             $this->success('上传成功!', 'personCenter');
         } else {
             $this->error('修改失败!');
         }
     } else {
         $upload = new \Think\Upload();
         // 实例化上传类
         $user['US_image'] = '/zhaoping/Public/Common/User/' . $_FILES['US_image']['name'][0];
         $upload->maxSize = 3145728;
         // 设置附件上传大小
         $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
         // 设置附件上传类型
         $upload->rootPath = './Public/Common/User/';
         // 设置附件上传根目录
         $upload->savePath = '';
         // 设置附件上传目录
         $oldImage = $User->getUserInfo($user['US_id'])[0];
         $path = '.' . substr($oldImage['US_image'], 9, 200);
         $info = $upload->upload();
         if (!$info) {
             // 上传错误提示错误信息
             $this->error($upload->getError());
         } else {
             // 上传成功
             //删除旧的图片
             if (strcmp($oldImage, $user['US_image']) != 0) {
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
             //添上新图
             $User->modifyUser($user);
             $image = new \Think\Image();
             $image->open($path);
             //将图片裁剪为120*160并保存为corp.jpg
             $image->thumb(120, 160, \Think\Image::IMAGE_THUMB_FIXED)->save($path);
             $this->success('上传成功!');
         }
     }
 }
 public function posts4()
 {
     $m = new UserModel();
     $data = $m->relation('posts')->find();
     print_r($data);
 }
 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);
         }
     }
 }