用户登录显示系统错误没有返回特定提示

Blade 未结 1 478
lcb
lcb 剑童 2024-07-03 17:00

一、该问题的重现步骤是什么?

1. 用户输错验证码,或者密码

2. 弹出系统错误,没有返回指定的

3.很疑惑,什么也没有改框架


二、你期待的结果是什么?实际看到的又是什么?


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

单体springboot

四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

1条回答
  • 具体的代码看下

    作者追问:2024-07-03 17:07

    /*
    *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions are met:
    *
    *  Redistributions of source code must retain the above copyright notice,
    *  this list of conditions and the following disclaimer.
    *  Redistributions in binary form must reproduce the above copyright
    *  notice, this list of conditions and the following disclaimer in the
    *  documentation and/or other materials provided with the distribution.
    *  Neither the name of the dreamlu.net developer nor the names of its
    *  contributors may be used to endorse or promote products derived from
    *  this software without specific prior written permission.
    *  Author: Chill 庄骞 (smallchill@163.com)
    */
    package org.springblade.modules.auth.granter;

    import lombok.AllArgsConstructor;
    import org.springblade.common.cache.CacheNames;
    import org.springblade.core.log.exception.ServiceException;
    import org.springblade.core.redis.cache.BladeRedis;
    import org.springblade.core.tool.utils.DigestUtil;
    import org.springblade.core.tool.utils.Func;
    import org.springblade.core.tool.utils.StringUtil;
    import org.springblade.core.tool.utils.WebUtil;
    import org.springblade.modules.auth.enums.UserEnum;
    import org.springblade.modules.auth.provider.ITokenGranter;
    import org.springblade.modules.auth.provider.TokenParameter;
    import org.springblade.modules.auth.utils.TokenUtil;
    import org.springblade.modules.system.entity.Tenant;
    import org.springblade.modules.system.entity.UserInfo;
    import org.springblade.modules.system.service.ITenantService;
    import org.springblade.modules.system.service.IUserService;
    import org.springframework.stereotype.Component;

    import javax.servlet.http.HttpServletRequest;

    /**
    * 验证码TokenGranter
    *
    * @author Chill
    */
    @Component
    @AllArgsConstructor
    public class CaptchaTokenGranter implements ITokenGranter {

       public static final String GRANT_TYPE = "captcha";

       private final IUserService userService;
       private final ITenantService tenantService;
       private final BladeRedis bladeRedis;

       @Override
       public UserInfo grant(TokenParameter tokenParameter) {
          HttpServletRequest request = WebUtil.getRequest();

          String key = request.getHeader(TokenUtil.CAPTCHA_HEADER_KEY);
          String code = request.getHeader(TokenUtil.CAPTCHA_HEADER_CODE);
          // 获取验证码
          String redisCode = bladeRedis.get(CacheNames.CAPTCHA_KEY + key);
          // 判断验证码
          if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) {
             throw new ServiceException(TokenUtil.CAPTCHA_NOT_CORRECT);
          }

          String tenantId = tokenParameter.getArgs().getStr("tenantId");
          String username = tokenParameter.getArgs().getStr("username");
          String password = tokenParameter.getArgs().getStr("password");
          UserInfo userInfo = null;
          if (Func.isNoneBlank(username, password)) {
             // 获取租户信息
             Tenant tenant = tenantService.getByTenantId(tenantId);
             if (TokenUtil.judgeTenant(tenant)) {
                throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
             }
             // 获取用户类型
             String userType = tokenParameter.getArgs().getStr("userType");
             // 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
             if (userType.equals(UserEnum.WEB.getName())) {
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.WEB);
             } else if (userType.equals(UserEnum.APP.getName())) {
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.APP);
             } else {
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.OTHER);
             }
          }
          return userInfo;
       }

    }


    0 讨论(0)
提交回复