feat: admin log aspect
This commit is contained in:
51
app/Aspect/Admin/AdminLoginLogAspect.php
Normal file
51
app/Aspect/Admin/AdminLoginLogAspect.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Aspect\Admin;
|
||||
|
||||
use App\Exception\AdminException;
|
||||
use App\Service\Admin\User\LoginService;
|
||||
use Hyperf\Di\Annotation\Aspect;
|
||||
use Hyperf\Di\Aop\AbstractAspect;
|
||||
use Hyperf\Di\Aop\ProceedingJoinPoint;
|
||||
use Hyperf\Di\Exception\Exception;
|
||||
|
||||
#[Aspect]
|
||||
class AdminLoginLogAspect extends AbstractAspect
|
||||
{
|
||||
/**
|
||||
* 需要切入的类
|
||||
* @var array|\class-string[]
|
||||
*/
|
||||
public array $classes = [
|
||||
// LoginService::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 需要切入的注解
|
||||
* @var array
|
||||
*/
|
||||
public array $annotations = [
|
||||
// SomeAnnotation::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 切入后处理逻辑
|
||||
* @param ProceedingJoinPoint $proceedingJoinPoint
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed
|
||||
{
|
||||
try {
|
||||
// 在调用前进行处理
|
||||
$result = $proceedingJoinPoint->process();
|
||||
// 在调用后进行处理
|
||||
//todo 登录日志是否需要
|
||||
|
||||
return $result;
|
||||
} catch (AdminException $e) {
|
||||
var_dump($e->getMessage());
|
||||
throw new AdminException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,22 @@ class LoginRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
|
||||
'account' => 'required|digits:11',
|
||||
'password' => 'required|string|min:6',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'account.required' => '请输入账号',
|
||||
'account.digits' => '账号格式错误',
|
||||
'password.required' => '请输入密码',
|
||||
'password.min' => '密码不能小于6位'
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'login' => ['account', 'password'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -14,11 +14,9 @@ use App\Constants\Admin\UserCode;
|
||||
use App\Constants\AdminCode;
|
||||
use App\Exception\AdminException;
|
||||
use App\Extend\SystemUtil;
|
||||
use App\Lib\AdminReturn;
|
||||
use App\Lib\Crypto\CryptoFactory;
|
||||
use App\Model\AdminUser;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\Common\AppMakeService;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
@@ -51,7 +49,9 @@ class LoginService extends BaseService
|
||||
|
||||
if ($userInfo->status == UserCode::DISABLE) throw new AdminException(UserCode::getMessage($userInfo->status),AdminCode::LOGIN_ERROR);
|
||||
|
||||
if ($this->cryptoFactory->cryptoClass('admin-password',$this->request->input('password'),$userInfo->salt) != $userInfo->password) throw new AdminException('密码错误!');
|
||||
// pass加密跟数据库做判断
|
||||
$password = $this->cryptoFactory->cryptoClass('admin-password',$this->request->input('password'),$userInfo->salt)->encrypt();
|
||||
if ($password != $userInfo->password) throw new AdminException('密码错误!');
|
||||
|
||||
$userInfo->last_login_time = date('Y-m-d H:i:s');
|
||||
$userInfo->last_login_ip = SystemUtil::getClientIp();
|
||||
@@ -59,6 +59,7 @@ class LoginService extends BaseService
|
||||
|
||||
if (!$userInfo->save()) throw new AdminException('登录失败');
|
||||
|
||||
//生成 token
|
||||
$token = $this->cryptoFactory->cryptoClass('jwt',json_encode([
|
||||
'id' => $userInfo->id,
|
||||
'role' => $userInfo->role_id,
|
||||
|
||||
Reference in New Issue
Block a user