123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- <?php
-
- namespace bibidd\Controller;
- use Bibidd\Controller\CommonBaseController;
- use DateTime;
-
- class UserController extends CommonBaseController
- {
-
-
-
- //封装返回的数据
- protected function returnData()
- {
- header('Access-Control-Allow-Origin: *');
- $data['status'] = '0';
- $data['code'] = '202';//未携带参数,请求失败
- $data['message'] = 'error';
- return $data;
- }
-
- /**
- * 用户注册时输入判断 用户名是否已被占用
- * @param $templateid []
- * @return $type 消息类型
- * //Error! Please enter another username
- */
- public function create_account_check()
- {
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: text/html; charset=utf-8');
- // 指定允许其他域名访问
-
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with,content-type');
- if (!empty($_POST)) {
- $username = $_POST['bibidd_username'];
- //查询是否存在 以用来判断是否唯一
- $yn_username = M("user_info")->where("name='$username'")->getField("name");
- if (!empty($yn_username)) {
- $data['status'] = '2';
- $data['message'] = 'Error! Please enter another username';//已存在
- echo json_encode($data);
- } else {
- $type = md5($username);
- $data['status'] = '1';
- $data['message'] = 'true';//通过
- echo json_encode($data);
- }
- } else {
- $data=$this->returnData();
- echo json_encode($data);
- }
- }
-
-
- /**
- * 登录认证
- *
- * 首先判断是否存在该用户
- * 再次判断 该用户密码是否正确
- * @param bibidd_username [用户名称]
- * @param bibidd_password [账号密码]
- * @return $type 消息类型
- */
- public function login_authenticate()
- {
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: text/html; charset=utf-8');
- // 指定允许其他域名访问
-
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with,content-type');
- if (!empty($_POST)) {
- $username = $_POST['bibidd_username'];
- $password = $_POST['bibidd_password'];
-
- $user_id = M("user_info")->where("name='$username'")->field('id,password,name')->select();
- if (!empty($user_id)) {
- $user_password = $user_id[0]['password'];
- if ($password==$user_password) {
- //记录登录
- $_POST['time'] = date("Y-m-d D h:i:s A",time());
- $_POST['code'] = '登录成功';
- M("loser_login")->add($_POST);
- //更改上次登录时间
- $last_login_list['last_login_time'] = time();
- M("user_info")->where("name='$username'")->save($last_login_list);
- $data['success'] = $user_id[0]['id'];
- $data['nickname'] = $user_id[0]['name'];
- echo json_encode($data);
- } else {
- $_POST['time'] = date("Y-m-d D h:i:s A",time());
- $_POST['code'] = '登录失败';
- M("loser_login")->add($_POST);
- $data['status'] = '0';
- $data['message'] = 'Invalid username/password!';
- echo json_encode($data);
- }
- }else{
- $data['status'] = '0';
- $data['message'] = 'Invalid username/password!';
- echo json_encode($data);
- }
-
- } else {
- echo $this->returnData();
- }
- }
-
-
- /**
- *获取用户IP地址
- * @param int $type
- * @return mixed
- */
- private function get_bb_ip($type = 0)
- {
- $type = $type ? 1 : 0;
- static $ip = NULL;
- if ($ip !== NULL) return $ip[$type];
- if ($_SERVER['HTTP_X_REAL_IP']) {//nginx 代理模式下,获取客户端真实IP
- $ip = $_SERVER['HTTP_X_REAL_IP'];
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {//客户端的ip
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {//浏览当前页面的用户计算机的网关
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos) unset($arr[$pos]);
- $ip = trim($arr[0]);
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];//浏览当前页面的用户计算机的ip地址
- } else {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // IP地址合法验证
- $long = sprintf("%u", ip2long($ip));
- $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
- return $ip[$type];
- }
-
-
- /**
- * slgj用户注册
- */
- public function slUserRegister()
- {
- header('Content-Type:text/json;charset=utf-8');
- header('Access-Control-Allow-Origin:*');
- header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
- header('Access-Control-Allow-Methods:POST');
- header('Access-Control-Expose-Headers:*');
- if (!empty($_POST)) {
- $account = $_POST['account']; //用户账号
- $password = $_POST['password'];
- $ddapp = $_POST['ddapp'];
- $device_type = $_POST['deviceType'];
- $invitation_code = $_POST['invitationCode'];
- //验证密码,正则表达式:必须包含至少一个字母和一个数字,且长度至少为8位
- $pattern = '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/';
- if(!preg_match($pattern,$password))
- {
- $this->returnDataAndSendMsg("密码必须是数字加字母组合,且长度不能少于8位");
- die();
- }
-
- $isRegiest = M("user_info")->where("name='$account'")->find();
- $userip = $this->get_bb_ip();
- if('111.25.20.29'==$userip)
- {
- die();
- }
- if (!empty($isRegiest)) {
- $data['code'] = '203';
- $data['msg'] = 'You have an account. Go log in';
- echo json_encode($data);
- die;
- } else {
- $arr['name'] = $account;
- $arr['password'] = $this->SHA256Hex($password);
- // $arr['nickname'] = '';
- $arr['add_time'] = time();
- $arr['userip'] = $userip;
- $wula_time = date("Y-m-d H:i:s",time());
- $arr['add_date'] = $wula_time;
- $arr['add_url'] = $ddapp;
- $arr['device_type'] = $device_type;
- $arr['balance'] = 30;//新增用户添加30余额
- $arr['register_invitation_code'] = $invitation_code;//邀请码
- $ret = M("user_info")->data($arr)->add();
- $this->proxy_reg_count($invitation_code,$ret,$account,$arr['add_time']);
- if($ret) {
- $find = "9169dd.app";
- $position = strpos($ddapp, $find);
- if ($position !== false) {
- $dd_uid = $ret;
- $ddapp_list['uid'] = $dd_uid;
- $ddapp_list['date'] = $wula_time ;
- M("ddapp_user")->add($ddapp_list);
- }
- $data['code'] = '200';
- $data['msg'] = 'Registered successfully';
- echo json_encode($data);
- } else {
- $data['code'] = '201';
- $data['code'] = 'Registration failed. Please try again';
- echo json_encode($data);
- }
- }
- } else {
- $data['code'] = '202';
- $data['msg'] = 'Incorrect parameters'; // 参数不正确
- echo json_encode($data);
- die;
- }
- }
-
-
- /**
- * @notes slgj用户登录
- */
- public function slUserLogin()
- {
- header('Content-Type:text/json;charset=utf-8');
- header('Access-Control-Allow-Origin:*');
- header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
- header('Access-Control-Allow-Methods:POST');
- header('Access-Control-Expose-Headers:*');
- if (!empty($_POST)) {
- if(empty($_POST['deviceType']))
- {
- $this->returnDataAndSendMsg("非法请求");
- die();
- }
- $account = $_POST['account'];
- $password = $_POST['password'];
- $isHavePhone = M("user_info")->where("name='$account'")->find();
- if (empty($isHavePhone)) {
- $data['code'] = '203';
- $data['msg'] = 'The account is not detected'; //未检测到该账号
- $data['user_id'] = '';
- echo json_encode($data);
- die;
- } else {
- $isRegiest = M("user_info")->where("name='$account' and password='$password'")->find();
- if (empty($isRegiest))
- {
- $pwd = $this->SHA256Hex($password);
- $isRegiest = M("user_info")->where("name='$account' and password='$pwd'")->find();
- }
- if (!empty($isRegiest)) {
- //防止代理登录,必须保证登录的域名是自己的域名
- if (empty($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], '6icb5zio55m76k6w5lqg5oml.app') === false) {
- // 满足条件的情况:
- $data['code'] = '200';
- $data['token']='0e41337ceef549c8ad8d8ca1a9446f1c';
- $data['user_id']='2364985';
- $data['zhibo']='1';
- $data['msg']='Login successful';
- $data['tel']='13967099131';
- die();
- }
- $data['code'] = '200';
- $data['msg'] = 'Login successful'; //登录成功
- $nowtime = time();
- M("user_info")->where(array("id" => $isRegiest['id']))->save(array("lastlogintime" => $nowtime));
- $data['user_id'] = $isRegiest['id'];
- $data['tel'] = $isRegiest['tel_phone'];
- $data['zhibo'] = $isRegiest['zhibo_account'];
- //下发token
- $data['token'] = $this->genToken($isRegiest['id']);
- echo json_encode($data);
- //更新请求
- $uid = $isRegiest['id'];
- $jintian_riqi = date("Y-m-d");
- M("huoyue_list")->where("uid='$uid' and today='$jintian_riqi'")->delete();
- $add_list['today'] = $jintian_riqi;
- $add_list['time'] = time();
- $add_list['uid'] = $uid;
- $add_list['device_type'] = $_POST['deviceType'];
- $add_list['url'] = $_SERVER['HTTP_REFERER'];
- M("huoyue_list")->add($add_list);
- } else {
- $data['code'] = '201';
- $data['msg'] = 'The account or password is incorrect'; //账号或密码不正确
- $data['user_id'] = '';
- echo json_encode($data);
- die;
- }
- }
- } else {
- $data['code'] = '202';
- $data['msg'] = 'Incorrect parameters'; // 参数不正确
- echo json_encode($data);
- die;
- }
- }
- /**
- *
- * 获取用户金币签到时间
- * @return void
- */
- public function get_user_coins_sign_time()
- {
- $this->addHeaders(); //添加头部请求
- $this->checkUserIsExist($_POST['uid']); //检查用户
- $uid=$_POST['uid'];
- $last_time = date('Y-m-d 00:00:00');
- $user_info = M("user_info")->field("last_sign_time")->where("id='$uid'")->find();
- $data['isSignTody'] = 'no';
- if(!empty( $user_info["last_sign_time"]) && $user_info["last_sign_time"]==$last_time)
- {
- $data['isSignTody'] = 'yes';
- }
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['data'] = $user_info["last_sign_time"];
- echo json_encode($data);
- }
- /**
- * 用户金币签名
- * @return void
- */
- public function user_coins_sign()
- {
- // $this->addHeaders(); //添加头部请求
- // $this->checkUserIsExist($_POST['uid']); //检查用户
- //
- // $uid=$_POST['uid'];
- // $sign_time = date('Y-m-d 00:00:00');
- //
- // $user_info = M("user_info")->field("gold_coins_number,last_sign_time")->where("id='$uid'")->find();
- // if($user_info['last_sign_time']==$sign_time)
- // {
- // //重复签到
- // $data['code'] = '200';
- // $data['message'] = 'ok';
- // $data['data'] = 0;
- // echo json_encode($data);
- // die();
- // }
- //
- //
- // $user_info['gold_coins_number']+=1;
- // $user_info['last_sign_time']=$sign_time;
- // $rs = M("user_info")->where("id='$uid'")->save($user_info);
- //
- // //添加统计
- // $tongji_info = M("user_sign_coins")->where("user_id='$uid'")->find();
- // if(empty($tongji_info))
- // {
- // $tongji_info['user_id']=$uid;
- // $tongji_info['lianxu_days']=1;
- // $tongji_info['last_sign']=date('Y-m-d H:i:s');
- // $rs = M("user_sign_coins")->add($tongji_info);
- // }else
- // {
- // $date = new DateTime($tongji_info['last_sign']);
- // $yesterday = new DateTime('-1 day');
- //
- // $formattedDate = $date->format('Y-m-d');
- // $formattedYesterday = $yesterday->format('Y-m-d');
- // if ($formattedDate == $formattedYesterday)
- // {
- // //昨天
- // $tongji_info['lianxu_days']+=1;
- // }else{
- // $tongji_info['lianxu_days']=1;
- // }
- //
- // $tongji_info['last_sign']=date('Y-m-d H:i:s');
- // $rs = M("user_sign_coins")->save($tongji_info);
- // }
- //
- // $data['code'] = '200';
- // $data['message'] = 'ok';
- // $data['data'] = $rs;
- // echo json_encode($data);
- }
- /**
- *
- * 判断用户注册时间是否在30分钟
- * @return void
- */
- public function is_reg_in_30()
- {
- $this->addHeaders(); //添加头部请求
- $user_info = $this->checkUserIsExist($_POST['uid']); //检查用户
- $uid=$user_info['id'];
- $reg_time =$user_info['add_date'];
- $rs['isIn30'] = false;
- //判断用户注册时间是否在30分钟内
- if(empty($reg_time))
- {
- $this->returnDataAndSendMsg("非法用户");
- die();
- }
- $currentTime = time();
- $inputTime = strtotime($reg_time);
- $difference = abs($currentTime - $inputTime);
- if($difference <= 1800)
- {
- $rs['isIn30'] = true;
- $rs['seconds']=1800-$difference;
- }
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['data'] = $rs;
- echo json_encode($data);
- }
- /**
- * 获取用户信息
- * @return void
- */
- public function get_user_info()
- {
- $this->addHeaders(); //添加头部请求
- $user_info = $this->checkUserIsExist($_POST['uid']); //检查用户
- //$uid=$user_info['id'];
- unset($user_info['name']);
- unset($user_info['password']);
- unset($user_info['ip_address']);
- unset($user_info['userip']);
- unset($user_info['id']);
- unset($user_info['device_type']);
- unset($user_info['beizhu']);
- unset($user_info['add_url']);
- unset($user_info['tel_phone']);
- unset($user_info['zhibo_account']);
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['data'] = $user_info;
- echo json_encode($data);
- }
- /**
- * 修改密码
- * @return void
- */
- public function modify_pwd()
- {
- $this->addHeaders(); //添加头部请求
- $user_info = $this->checkUserIsExist($_POST['uid']); //检查用户
- $uid = $user_info['id'];
- $oldPwd = $_POST['oldPwd'];
- $password = $_POST['password'];
- if(empty($password) || empty(trim($password))||empty(oldPwd) || empty(trim(oldPwd)))
- {
- $this->returnDataAndSendMsg("密码或旧密码不能为空");
- die();
- }
- //判断历史密码是否正确
- $old_id = M("user_info")->where("id=$uid AND password='$oldPwd'")->getField("id");
- if(empty($old_id))
- {
- $oldPwd=$this->SHA256Hex($oldPwd);
- $old_id = M("user_info")->where("id=$uid AND password='$oldPwd'")->getField("id");
- if(empty($old_id))
- {
- $this->returnDataAndSendMsg("旧密码错误");
- die();
- }
- }
- $pwd=$this->SHA256Hex($password);
- $rs = M("user_info")->where("id=$uid")->setField("password",$pwd);
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['data'] = $rs;
- echo json_encode($data);
- }
- }
|