1
luodangjia
2025-01-22 759e0540a7ca20f33ab265d00e7944e4f18a562b
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
@@ -23,12 +23,14 @@
import com.ruoyi.company.api.model.RegisterUser;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.AppUser;
import com.ruoyi.system.api.model.LoginUser;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
@@ -170,6 +172,7 @@
            if (l1 - l > 2 * 60 * 1000) {
                throw new CaptchaException("验证码已失效");
            }
            captcha = split[0];
            if (!smsCode.equalsIgnoreCase(captcha)) {
                throw new CaptchaException("验证码错误");
            }
@@ -220,6 +223,20 @@
        if (R.isError(r)) {
            throw new ServiceException(r.getMsg());
        }
        forceLogout(user.getUserId());
    }
    public void forceLogout(Long userId) {
        Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
        for (String key : keys) {
            Object user = redisService.getCacheObject(key);
            if (user instanceof AppUser) {
                AppUser appUser = (AppUser) user;
                if (appUser.getUserId().equals(userId)) {
                    redisService.deleteObject(key);
                }
            }
        }
    }