From 6e82cd5d5875b38fb30be5ee4c1c5d3dbe33fe98 Mon Sep 17 00:00:00 2001 From: rentaiming <806181062@qq.com> Date: 星期二, 28 五月 2024 17:31:46 +0800 Subject: [PATCH] 写用户端接口 --- 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