checktoken($token); if($res == -1){ return $res; } $user_id = explode('/',base64_decode($token))['2']; $userInfo = db('accounts')->where('id', $user_id)->find(); //print_r($userInfo);exit; $this->assign([ 'userInfo' => $userInfo ]); return $this->fetch(); } // 修改密码 public function uqdatePwd() { $token = input("param.token/s"); $res = model('Accounts')->checktoken($token); if($res == -1){ return $res; } $user_id = explode('/',base64_decode($token))['2']; if(request()->isPost()){ $password = input("param.password/s"); $newPassword = input("param.newPassword/s"); $confirmPassword = input("param.confirmPassword/s"); } if(empty($password)){ return json(['code' => -1, 'data' => '', 'msg' => '原密码不能为空']); } if(empty($newPassword)){ return json(['code' => -2, 'data' => '', 'msg' => '新密码不能为空']); } if(empty($confirmPassword)){ return json(['code' => -3, 'data' => '', 'msg' => '确认新密码不能为空']); } if($newPassword != $confirmPassword){ return json(['code' => -3, 'data' => '', 'msg' => '新密码不一致']); } $userInfo = db('accounts')->where('id', $user_id)->find(); if(md5($password . config('salt')) != $userInfo['password']){ return json(['code' => -3, 'data' => '', 'msg' => '原密码不正确']); } $param = [ 'password' => md5($newPassword . config('salt')) ]; try{ db('accounts')->where('id', $user_id)->update($param); }catch(\Exception $e){ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => url('user/index'), 'msg' => '密码修改成功']); } // 用户留言 public function LeavingMessage() { if(request()->isPost()){ $account_id = input("param.account_id/s"); $nick_name = input("param.nick_name/s"); $email = input("param.email/s"); $phone = input("param.phone/s"); $content = input("param.content/s"); $account_ip = $_SERVER["REMOTE_ADDR"]; //获得访问者浏览器 $browse = $this->browse_info(); //获得访客操作系统 $system = $this->get_os(); $image = input("param.file/s"); if(empty($account_id)){ return json(['code' => -1, 'data' => '', 'msg' => '用户id不能为空']); } // if(empty($email)){ // return json(['code' => -2, 'data' => '', 'msg' => '邮箱不能为空']); // } // if(empty($qq)){ // return json(['code' => -3, 'data' => '', 'msg' => 'QQ不能为空']); // } // if(empty($wechat)){ // return json(['code' => -4, 'data' => '', 'msg' => '微信不能为空']); // } // if(empty($content)){ // return json(['code' => -5, 'data' => '', 'msg' => '内容不能为空']); // } // if(empty($phone)){ // return json(['code' => -6, 'data' => '', 'msg' => '电话不能为空']); // } // if(empty($image)){ // return json(['code' => -7, 'data' => '', 'msg' => '附件不能为空']); // } $param = [ 'account_id' => $account_id, 'content' => $content, 'account_ip' => $account_ip, 'browse' => $browse, 'system' => $system, 'image' => $image, 'message_status' => 0, 'add_time' => time() ]; $info = array(); if(!empty($nick_name)){ $param['nick_name'] = $nick_name; $info['nick_name'] = $nick_name; } if(!empty($email)){ $param['email'] = $email; $info['account_email'] = $email; } if(!empty($phone)){ $param['phone'] = $phone; $info['account_phone'] = $phone; } try{ db('accountsmessage')->insertGetId($param); if(!empty($info)){ db('accounts')->where('id',$account_id)->update($info); } }catch(\Exception $e){ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => url('user/index'), 'msg' => '留言成功']); } } // 上传图片 public function uplodeImg() { if(request()->isPost()){ $file = request()->file('file'); if(empty($file)){ return json(['code' => -7, 'data' => '', 'msg' => '附件不能为空']); } $fileInfo = $file->getInfo(); /*if($fileInfo['size'] > 1024 * 1024 * 2){ // 上传失败获取错误信息 return json( ['code' => -8, 'data' => '', 'msg' => '文件超过2M'] ); }*/ //检测图片格式 $ext = explode('.', $fileInfo['name']); $ext = array_pop($ext); $extArr = explode('|', 'jpg|png|gif|jpeg'); if(!in_array($ext, $extArr)){ return json(['code' => -9, 'data' => '', 'msg' => '只能上传jpg|png|gif|jpeg的文件']); } // 移动到框架应用根目录/public/uploads/ 目录下 $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'); if($info){ $src = '/uploads' . '/' . date('Ymd') . '/' . $info->getFilename(); }else{ // 上传失败获取错误信息 return json(['code' => -10, 'data' => '', 'msg' => $file->getError()]); } } } /** * 获得访客操作系统 * @return string */ // public static function get_os(){ // if (!empty($_SESSION['userAgent'])) { // $os = $_SESSION['userAgent']; // if (preg_match('/win/i', $os)) { // $os = 'Windows'; // } else if (preg_match('/mac/i', $os)) { // $os = 'MAC'; // } else if (preg_match('/linux/i', $os)) { // $os = 'Linux'; // } else if (preg_match('/unix/i', $os)) { // $os = 'Unix'; // } else if (preg_match('/bsd/i', $os)) { // $os = 'BSD'; // } else { // $os = 'Other'; // } // return $os; // } else { // return 'unknow'; // } // } function get_os() { $agent = $_SERVER['HTTP_USER_AGENT']; $os = false; if (stristr($agent,'win')) { $os = 'Windows'; } else if (stristr($agent,'win') && stristr($agent, '95')) { $os = 'Windows 95'; } else if (stristr($agent,'win 9x') && stristr($agent, '4.90')) { $os = 'Windows ME'; } else if (stristr($agent,'win') && stristr($agent,'98')) { $os = 'Windows 98'; } else if (stristr($agent,'win') && stristr($agent,'nt 5.1')) { $os = 'Windows XP'; } else if (stristr($agent,'win') && stristr($agent,'nt 5')) { $os = 'Windows 2000'; } else if (stristr($agent,'win') && stristr($agent,'nt')) { $os = 'Windows NT'; } else if (stristr($agent,'win') && stristr($agent,'32')) { $os = 'Windows 32'; } else if (stristr($agent,'linux')) { $os = 'Linux'; } else if (stristr($agent,'unix')) { $os = 'Unix'; } else if (stristr($agent,'sun') && stristr($agent,'os')) { $os = 'SunOS'; } else if (stristr($agent,'ibm') && stristr($agent,'os')) { $os = 'IBM OS/2'; } else if (stristr($agent,'Mac')) { $os = 'Mac OS X'; } else if (stristr($agent,'PowerPC')) { $os = 'PowerPC'; } else if (stristr($agent,'AIX')) { $os = 'AIX'; } else if (stristr($agent,'HPUX')) { $os = 'HPUX'; } else if (stristr($agent,'NetBSD')) { $os = 'NetBSD'; } else if (stristr($agent,'BSD')) { $os = 'BSD'; } else if (stristr($agent,'OSF1')) { $os = 'OSF1'; } else if (stristr($agent,'IRIX')) { $os = 'IRIX'; } else if (stristr($agent,'FreeBSD')) { $os = 'FreeBSD'; } else if (stristr($agent,'teleport')) { $os = 'teleport'; } else if (stristr($agent,'flashget')) { $os = 'flashget'; } else if (stristr($agent,'webzip')) { $os = 'webzip'; } else if (stristr($agent,'offline')) { $os = 'offline'; } else{ $os = ''; } return $os; } /** * 获得访问者浏览器 * @return string */ // public static function browse_info(){ // if (!empty($_SESSION['userAgent'])) { // $br = $_SESSION['userAgent']; // if (preg_match('/MSIE/i', $br)) { // $br = 'MSIE'; // } else if (preg_match('/Firefox/i', $br)) { // $br = 'Firefox'; // } else if (preg_match('/Chrome/i', $br)) { // $br = 'Chrome'; // } else if (preg_match('/Safari/i', $br)) { // $br = 'Safari'; // } else if (preg_match('/Opera/i', $br)) { // $br = 'Opera'; // } else { // $br = 'Other'; // } // return $br; // } else { // return 'unknow'; // } // } public function browse_info(){ if(!empty($_SERVER['HTTP_USER_AGENT'])){ $br = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/MSIE/i',$br)) { $br = 'MSIE'; } elseif (preg_match('/Firefox/i',$br)) { $br = 'Firefox'; } elseif (preg_match('/Chrome/i',$br)) { $br = 'Chrome'; } elseif (preg_match('/Safari/i',$br)) { $br = 'Safari'; } elseif (preg_match('/Opera/i',$br)) { $br = 'Opera'; }else { $br = 'Other'; } return $br; } else{ return "unknow"; } } }