From fb88391ffa5e2dbaaccccffd65ae127382df8126 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期三, 05 三月 2025 16:47:35 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/xiaochen991015/xizang --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index eadb4d3..e54ccc2 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -2,8 +2,14 @@ import javax.annotation.Resource; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.core.domain.entity.TTenantResp; +import com.ruoyi.common.core.domain.model.LoginUserApplet; import com.ruoyi.common.enums.UserStatus; +import com.ruoyi.system.model.TTenant; +import com.ruoyi.system.service.TTenantService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; @@ -52,6 +58,8 @@ @Autowired private ISysUserService userService; + @Autowired + private TTenantService tenantService; @Autowired private ISysConfigService configService; @@ -127,8 +135,6 @@ */ public LoginUser loginCode(String username,String code) { - - // 登录前置校验 if (StringUtils.isEmpty(username)){ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); @@ -163,6 +169,43 @@ return loginUser; } + /** + * 登录验证 + * + * @param username 用户名 + * @param code 验证码 + * @return 结果 + */ + public LoginUserApplet loginCodeApplet(String username, String code) + { + // 登录前置校验 + if (StringUtils.isEmpty(username)){ + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); + throw new UserNotExistsException(); + } + // 用户验证 + TTenant user = tenantService.getOne(Wrappers.<TTenant>lambdaQuery().eq(TTenant::getAccount,username)); + if (StringUtils.isNull(user)){ + log.info("登录用户:{} 不存在.", username); + throw new ServiceException(MessageUtils.message("user.not.exists")); + } else if (user.getDisabled()) { + log.info("登录用户:{} 已被删除.", username); + throw new ServiceException(MessageUtils.message("user.password.delete")); + } + // 校验验证码 + Object cacheObject = redisCache.getCacheObject(user.getAccount()); + if(!code.equals(String.valueOf(cacheObject))){ + log.info("登录用户:{} 短信验证码错误{}", username,code); + throw new ServiceException("短信验证码错误"); + } + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); + TTenantResp tTenantResp = new TTenantResp(); + BeanUtils.copyProperties(user,tTenantResp); + LoginUserApplet loginUser = new LoginUserApplet(user.getId(), null, tTenantResp, null); + // 生成token + return loginUser; + } + /** * 校验验证码 -- Gitblit v1.7.1