新增解析功能
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
namespace catchAdmin\login;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catchAdmin\system\model\LoginLog;
|
||||
use think\facade\Db;
|
||||
|
||||
class LoginLogEvent
|
||||
{
|
||||
public function handle($params)
|
||||
{
|
||||
$agent = request()->header('user-agent');
|
||||
|
||||
$username = Users::where('email', $params['email'])->value('username');
|
||||
|
||||
app(LoginLog::class)->storeBy([
|
||||
'login_name' => $username ? : $params['email'],
|
||||
'login_ip' => request()->ip(),
|
||||
'browser' => $this->getBrowser($agent),
|
||||
'os' => $this->getOs($agent),
|
||||
'login_at' => time(),
|
||||
'status' => $params['success'] ? 1 : 2,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @param $agent
|
||||
* @return string
|
||||
*/
|
||||
private function getOs($agent): string
|
||||
{
|
||||
if (false !== stripos($agent, 'win') && preg_match('/nt 6.1/i', $agent)) {
|
||||
return 'Windows 7';
|
||||
}
|
||||
if (false !== stripos($agent, 'win') && preg_match('/nt 6.2/i', $agent)) {
|
||||
return 'Windows 8';
|
||||
}
|
||||
if(false !== stripos($agent, 'win') && preg_match('/nt 10.0/i', $agent)) {
|
||||
return 'Windows 10';#添加win10判断
|
||||
}
|
||||
if (false !== stripos($agent, 'win') && preg_match('/nt 5.1/i', $agent)) {
|
||||
return 'Windows XP';
|
||||
}
|
||||
if (false !== stripos($agent, 'linux')) {
|
||||
return 'Linux';
|
||||
}
|
||||
if (false !== stripos($agent, 'mac')) {
|
||||
return 'mac';
|
||||
}
|
||||
|
||||
return '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @param $agent
|
||||
* @return string
|
||||
*/
|
||||
private function getBrowser($agent): string
|
||||
{
|
||||
if (false !== stripos($agent, "MSIE")) {
|
||||
return 'MSIE';
|
||||
}
|
||||
if (false !== stripos($agent, "Firefox")) {
|
||||
return 'Firefox';
|
||||
}
|
||||
if (false !== stripos($agent, "Chrome")) {
|
||||
return 'Chrome';
|
||||
}
|
||||
if (false !== stripos($agent, "Safari")) {
|
||||
return 'Safari';
|
||||
}
|
||||
if (false !== stripos($agent, "Opera")) {
|
||||
return 'Opera';
|
||||
}
|
||||
|
||||
return '未知';
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
namespace catchAdmin\login\controller;
|
||||
|
||||
use catchAdmin\login\request\LoginRequest;
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\LoginFailedException;
|
||||
|
||||
class Index extends CatchController
|
||||
{
|
||||
/**
|
||||
* 登陆
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param LoginRequest $request
|
||||
* @param CatchAuth $auth
|
||||
* @return bool|string
|
||||
*/
|
||||
public function login(LoginRequest $request, CatchAuth $auth)
|
||||
{
|
||||
$params = $request->param();
|
||||
|
||||
$token = $auth->attempt($params);
|
||||
|
||||
$user = $auth->user();
|
||||
|
||||
if ($user->status == Users::DISABLE) {
|
||||
throw new LoginFailedException('该用户已被禁用');
|
||||
}
|
||||
|
||||
// 记录用户登录
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->last_login_time = time();
|
||||
$user->save();
|
||||
|
||||
// 登录事件
|
||||
$params['success'] = $token;
|
||||
|
||||
event('loginLog', $params);
|
||||
|
||||
return $token ? CatchResponse::success([
|
||||
'token' => $token,
|
||||
], '登录成功') : CatchResponse::success('', '登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 登出
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param CatchAuth $auth
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function logout(CatchAuth $auth): \think\response\Json
|
||||
{
|
||||
if ($auth->logout()) {
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
return CatchResponse::fail('登出失败');
|
||||
}
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"name": "登陆",
|
||||
"alias": "login",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"order": 1,
|
||||
"services": [
|
||||
"catchAdmin\\login\\LoginService"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
namespace catchAdmin\login\request;
|
||||
|
||||
use catcher\base\CatchRequest;
|
||||
|
||||
class LoginRequest extends CatchRequest
|
||||
{
|
||||
protected $needCreatorId = false;
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
// TODO: Implement rules() method.
|
||||
return [
|
||||
'email|用户名' => 'email',
|
||||
'password|密码' => 'require',
|
||||
// 'captcha|验证码' => 'require|captcha'
|
||||
];
|
||||
}
|
||||
|
||||
protected function message(): array
|
||||
{
|
||||
// TODO: Implement message() method.
|
||||
return [];
|
||||
|
||||
}
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
<?php
|
||||
# 登入
|
||||
$router->post('login', '\catchAdmin\login\controller\Index@login');
|
||||
|
Reference in New Issue
Block a user