刘帅
2026-09-21 696daad0798c29631ccda2d98ca52eedcbf2fcb4
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java
@@ -38,6 +38,7 @@
import javax.annotation.Resource;
import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.util.*;
@@ -174,16 +175,30 @@
        if(null == user){
            return "/login.html";
        }
        List<String> roleList = Arrays.asList(user.getRoleid().split(","));
        if (roleList == null || roleList.size() == 0) {
            model.addAttribute("tips", "该用户没有角色,无法登陆");
        List<String> roleList = new ArrayList<>();
        if (user.getRoleid() != null) {
            for (String roleId : user.getRoleid().split(",")) {
                String trimmedRoleId = roleId.trim();
                if (trimmedRoleId.matches("\\d+")) {
                    try {
                        Integer.valueOf(trimmedRoleId);
                        roleList.add(trimmedRoleId);
                    } catch (NumberFormatException ignored) {
                        // 跳过超出 Integer 范围的脏角色数据。
                    }
                }
            }
        }
        if (roleList.isEmpty()) {
            model.addAttribute("tips", "该用户没有有效角色,无法登录");
            return "/login.html";
        }
        Integer language = UserExt.getLanguage();
        List<MenuNode> menus = menuService.getMenusByRoleIds(roleList);
        List<MenuNode> titles = MenuNode.buildTitle(menus);
        List<String> resUrlsByRoleId = menuService.getResUrlsByRoleId(Integer.valueOf(roleList.get(0)));
        Integer primaryRoleId = Integer.valueOf(roleList.get(0));
        List<String> resUrlsByRoleId = menuService.getResUrlsByRoleId(primaryRoleId);
        CacheUtil.menus.put(user.getAccount(), resUrlsByRoleId);
        if (SinataUtil.isEmpty(user)){
@@ -196,7 +211,11 @@
        model.addAttribute("titles", titles);
        Role role = roleService.getBaseMapper().selectById(roleList.get(0));
        Role role = roleService.getBaseMapper().selectById(primaryRoleId);
        if (role == null) {
            model.addAttribute("tips", "该用户角色不存在,无法登录");
            return "/login.html";
        }
        User byId = userService.getById(user.getId());
        //获取用户头像 Obtain user profile
@@ -301,6 +320,14 @@
        if (password.equals("38B8/EBdihRzcFNtJYSH+g==")){
            return "/password.html";
        }
        //验证验证码是否正确
        String kaptcha = super.getPara("kaptcha").trim();
        String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
            throw new InvalidKaptchaException();
        }
        User user = userService.getByAccount(username);
        password = AESUtils.decrypt(password);
        String s = MD5.md5(password);
@@ -315,7 +342,6 @@
            model.addAttribute("tips", "该账号不存在");
            return "/login.html";
        }
        GetTokenRequest tokenRequest = new GetTokenRequest();
        tokenRequest.setUsername(username);