ip
This commit is contained in:
parent
ec3f0b3a3d
commit
bbc831b4b5
@ -5,6 +5,7 @@ use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
use think\facade\Db;
|
||||
use think\facade\Session;
|
||||
use taoler\com\Api;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
@ -52,6 +53,24 @@ class User extends Model
|
||||
//将用户数据写入Session
|
||||
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);
|
||||
if($add->status == 'success'){
|
||||
$city = $add->city;
|
||||
} else {
|
||||
$city ='未知';
|
||||
}
|
||||
|
||||
Db::name('user')->where('id',$user['id'])->update(
|
||||
[
|
||||
'city' => $city,
|
||||
'last_login_ip' => $ip,
|
||||
'last_login_time' => time()
|
||||
]
|
||||
);
|
||||
|
||||
//查询结果1表示有用户,用户名密码正确
|
||||
return 1;
|
||||
}else{
|
||||
|
26
extend/taoler/com/Api.php
Normal file
26
extend/taoler/com/Api.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace taoler\com;
|
||||
|
||||
class Api
|
||||
{
|
||||
public static function urls($url)
|
||||
{
|
||||
if($url == ''){
|
||||
return json(['code'=>-1,'msg'=>'800']);
|
||||
}
|
||||
$ch =curl_init ();
|
||||
curl_setopt($ch,CURLOPT_URL, $url);
|
||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
||||
curl_setopt($ch,CURLOPT_POST, 1);
|
||||
$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'=>'Ô¶³Ì·þÎñÆ÷ʧ°Ü']);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,9 @@ layui.define(['table', 'form'], function(exports){
|
||||
,{field: 'email', title: '邮箱'}
|
||||
,{field: 'sex', width: 60, title: '性别',templet: '#sex'}
|
||||
,{field: 'ip', title: '登录IP'}
|
||||
,{field: 'jointime', title: '申请时间', sort: true}
|
||||
,{field: 'city', title: '城市'}
|
||||
,{field: 'logintime', title: '最后登录', sort: true}
|
||||
,{field: 'jointime', title: '注册时间', sort: true}
|
||||
,{field: 'check', title: '状态', templet: '#buttonCheck', minWidth: 80, align: 'center'}
|
||||
,{field: 'auth', title: '超级管理员', templet: '#buttonAuth', minWidth: 80, align: 'center'}
|
||||
,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
|
||||
|
Loading…
Reference in New Issue
Block a user