From 099ea14bba367fd86f0dde37d908f07cc04c3d39 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 10 四月 2025 15:38:01 +0800
Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/xizang

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java |   67 +++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 12 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..c7302b8 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
@@ -1,21 +1,15 @@
 package com.ruoyi.framework.web.service;
 
-import javax.annotation.Resource;
-
-import com.ruoyi.common.enums.UserStatus;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.stereotype.Component;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.entity.TTenantResp;
 import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.core.domain.model.LoginUserApplet;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.enums.UserStatus;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.exception.user.BlackListException;
 import com.ruoyi.common.exception.user.CaptchaException;
@@ -29,8 +23,20 @@
 import com.ruoyi.framework.manager.AsyncManager;
 import com.ruoyi.framework.manager.factory.AsyncFactory;
 import com.ruoyi.framework.security.context.AuthenticationContextHolder;
+import com.ruoyi.system.model.TTenant;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysUserService;
+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;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
 
 /**
  * 登录校验方法
@@ -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