This commit is contained in:
zhao 2020-03-18 21:30:30 +08:00
parent d079f03887
commit e8e5da04b0
6 changed files with 53 additions and 14 deletions

View File

@ -237,7 +237,7 @@ abstract class BaseController
protected function showUser()
{
//1.查询用户
$user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point')->where('id',Session::get('user_id'))->cache(600)->find();
$user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point,create_time')->where('id',Session::get('user_id'))->cache(600)->find();
//2.将User变量赋给模板 公共模板nav.html
View::assign('user',$user);
}

View File

@ -55,23 +55,24 @@ class User extends Model
Session::set('user_id',$user['id']);
Session::set('user_name',$user['name']);
$ip = request()->ip();
/*
$url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN';
//$url = 'http://ip-api.com/json/?lang=zh-CN';
$add = Api::urls($url);
$add = Api::urlGet($url);
if($add->status == 'success'){
$city = $add->city;
} else {
$city ='未知';
}
*/
Db::name('user')->where('id',$user['id'])->update(
[
'city' => $city,
//'city' => $city,
'last_login_ip' => $ip,
'last_login_time' => time()
]
);
Log::channel('login')->info('login:{user} {ip}:{city}',['user'=>$user['name'],'ip'=>$ip,'city'=>$city]);
Log::channel('login')->info('login:{user} {ip}',['user'=>$user['name'],'ip'=>$ip]);
//查询结果1表示有用户用户名密码正确
return 1;

View File

@ -254,11 +254,11 @@ class Article extends BaseController
{
$file = request()->file('file');
try {
validate(['file'=>'fileSize:2048|fileExt:jpg,png,gif'])
validate(['file'=>'fileSize:1024000|fileExt:jpg,png,gif'])
->check(['file'=>$file]);
$savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file);
} catch (ValidateException $e) {
echo $e->getMessage();
return json(['status'=>-1,'msg'=>$e->getMessage()]);
}
$upload = Config::get('filesystem.disks.public.url');

View File

@ -94,11 +94,11 @@ class User extends BaseController
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
validate(['file'=>'filesize:204800|fileExt:jpg,png,gif'])
->check(['file'=>$file]);
$savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
return json(['status'=>-1,'msg'=>$e->getMessage()]);
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){

View File

@ -4,7 +4,7 @@ namespace taoler\com;
class Api
{
public static function urls($url)
public static function urlPost($url, $data)
{
if($url == ''){
return json(['code'=>-1,'msg'=>'800']);
@ -14,6 +14,7 @@ class Api
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
@ -23,4 +24,44 @@ class Api
return json(['code'=>-1,'msg'=>'远程服务器失败']);
}
}
public static function urlGet($url)
{
$ch =curl_init ();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。 参数为1表示输出信息头,为0表示不输出
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode == '200'){
return json_decode($data);
} else {
return json(['code'=>-1,'msg'=>'远程服务器失败']);
}
}
public static function get_real_ip()
{
static $realip;
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$realip = $_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$realip = getenv('HTTP_X_FORWARDED_FOR');
} else if (getenv('HTTP_CLIENT_IP')) {
$realip = getenv('HTTP_CLIENT_IP');
} else {
$realip = getenv('REMOTE_ADDR');
}
}
return $realip;
}
}

View File

@ -2,9 +2,6 @@
Options +FollowSymlinks -Multiviews
RewriteEngine On
FileETag MTime Size
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f