From a22249bfe0ac068f7c2c0a167aa8102ea98def0e Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期二, 04 六月 2024 12:01:02 +0800
Subject: [PATCH] 提交LocalDateTime 序列化 反序列化配置
---
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java | 135 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
index 431c264..0c77097 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
@@ -1,7 +1,5 @@
package com.ruoyi.auth.service;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.SecurityConstants;
@@ -15,8 +13,16 @@
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.RemoteUserService;
+import com.ruoyi.system.api.domain.AppMiniLoginVO;
import com.ruoyi.system.api.domain.SysUser;
+import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO;
+import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO;
+import com.ruoyi.system.api.feignClient.MemberClient;
import com.ruoyi.system.api.model.LoginUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
/**
* 登录校验方法
@@ -37,6 +43,9 @@
@Autowired
private RedisService redisService;
+
+ @Resource
+ private MemberClient MemberClient;
/**
* 登录
@@ -101,6 +110,110 @@
return userInfo;
}
+
+ public AppMiniLoginVO miniLogin(AppMiniLoginDTO appMiniLoginDto)
+ {
+ // 查询用户信息
+ R<AppMiniLoginVO> userResult = MemberClient.miniLogin(appMiniLoginDto);
+ if (R.FAIL == userResult.getCode())
+ {
+ throw new ServiceException(userResult.getMsg());
+ }
+ AppMiniLoginVO userInfo = userResult.getData();
+ SysUser user = userInfo.getSysUser();
+ if(user!=null){
+ String username = user.getUserName();
+ // IP黑名单校验
+ String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
+ if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
+ throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
+ }
+ if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
+ throw new ServiceException(username,501);
+ }
+ if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+ throw new ServiceException(username,501);
+ }
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
+ }
+ return userInfo;
+ }
+
+ public AppMiniLoginVO miniRegister(AppMiniRegisterDTO appUserRegisterDto)
+ {
+ // 查询用户信息
+ R<AppMiniLoginVO> userResult = MemberClient.miniRegister(appUserRegisterDto);
+ if (R.FAIL == userResult.getCode())
+ {
+ throw new ServiceException(userResult.getMsg());
+ }
+ AppMiniLoginVO appMiniRegisterVo = userResult.getData();
+ SysUser user=appMiniRegisterVo.getSysUser();
+ if(appMiniRegisterVo.getSysUser()!=null){
+ String username = user.getUserName();
+ // IP黑名单校验
+ String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
+ if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
+ throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
+ }
+ if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
+ throw new ServiceException("对不起,您的账号: 已被删除");
+ }
+ if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+ throw new ServiceException("对不起,您的账号: 已停用");
+ }
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
+ }
+ return appMiniRegisterVo;
+ }
+
+ public AppMiniLoginVO actionMiniLogin(AppMiniLoginDTO appMiniLoginDto)
+ {
+ // 查询用户信息
+ R<AppMiniLoginVO> userResult = MemberClient.actionMiniLogin(appMiniLoginDto);
+ if (R.FAIL == userResult.getCode())
+ {
+ throw new ServiceException(userResult.getMsg());
+ }
+ AppMiniLoginVO userInfo = userResult.getData();
+ SysUser user = userInfo.getSysUser();
+ if(user!=null){
+ String username = user.getUserName();
+ // IP黑名单校验
+ String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
+ if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
+ throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
+ }
+ if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
+ throw new ServiceException(username,501);
+ }
+ if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
+ {
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+ throw new ServiceException(username,501);
+ }
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
+ }
+ return userInfo;
+ }
+
+
public void logout(String loginName)
{
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
@@ -140,4 +253,22 @@
}
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
}
+
+ public void changePassword(String username, String password, String verificationCode) {
+ String verificationCodeCache = Convert.toStr(
+ redisService.getCacheObject(
+ CacheConstants.CHANGE_PASSWORD_CAPTCHA_CODE_KEY + username));
+ if (StringUtils.isEmpty(verificationCodeCache)) {
+ throw new ServiceException("验证码已过期,请重新获取!");
+ }
+ if (!verificationCodeCache.equals(verificationCode)) {
+ throw new ServiceException("验证码错误,请重新输入!");
+ }
+ R<LoginUser> userInfo = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
+ if (R.FAIL == userInfo.getCode()) {
+ throw new ServiceException(userInfo.getMsg());
+ }
+ remoteUserService.changePassword(username, SecurityUtils.encryptPassword(password),
+ SecurityConstants.INNER);
+ }
}
--
Gitblit v1.7.1