智慧保安后台管理-外网项目备份
Administrator
2022-01-05 fefb66281d68875d1a05d3940fb2b45651801b25
登录逻辑修改,考试系统考生登录系统没有考试信息则不予登录
2 files modified
39 ■■■■ changed files
src/main/java/org/springblade/modules/auth/endpoint/BladeTokenEndPoint.java 37 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/auth/endpoint/BladeTokenEndPoint.java
@@ -40,12 +40,16 @@
import org.springblade.modules.auth.provider.TokenGranterBuilder;
import org.springblade.modules.auth.provider.TokenParameter;
import org.springblade.modules.auth.utils.TokenUtil;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.vo.ExamPaperVO;
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.zc.service.IZcService;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import static org.springblade.core.cache.constant.CacheConstant.*;
@@ -66,13 +70,23 @@
    private final BladeRedis bladeRedis;
    private final JwtProperties jwtProperties;
    private final IZcService iZcService;
    private final ExamPaperService examPaperService;
    /**
     * 登录
     * @param tenantId
     * @param username
     * @param password
     * @param loginType 1:考试系统登录 ,没有值则走其他登录逻辑
     * @return
     */
    @ApiLog("登录用户验证")
    @PostMapping("/oauth/token")
    @ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password")
    @ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password,登录类型:loginType")
    public Kv token(@ApiParam(value = "租户ID", required = true) @RequestParam String tenantId,
                    @ApiParam(value = "账号", required = true) @RequestParam(required = false) String username,
                    @ApiParam(value = "密码", required = true) @RequestParam(required = false) String password) {
                    @ApiParam(value = "密码", required = true) @RequestParam(required = false) String password,
                    @RequestParam(required = false) Integer loginType) {
        Kv authInfo = Kv.create();
        String s = iZcService.selectType(username);
@@ -88,8 +102,8 @@
        ITokenGranter granter = TokenGranterBuilder.getGranter(grantType);
        UserInfo userInfo = granter.grant(tokenParameter);
        if (null!=s && s.equals("")) {
        //校验
        if (null != s && s.equals("")) {
            if (s.equals("0")) {
                return authInfo.set("error_description", "用户未审核");
            }
@@ -97,7 +111,7 @@
                return authInfo.set("error_description", "审核不通过");
            }
        }
        if (userInfo == null || userInfo.getUser() == null ) {
        if (userInfo == null || userInfo.getUser() == null) {
            return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户名或密码不正确");
        }
@@ -105,6 +119,19 @@
            return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "未获得用户的角色信息");
        }
        if (null!=loginType) {
            //如果是考试系统登录
            if (loginType.equals(1)) {
                //判断角色
                if (!userInfo.getRoles().get(0).equals("培训公司管理员")) {
                    //查询考生考试信息
                    List<ExamPaperVO> examDetail = examPaperService.getExamDetail(userInfo.getUser().getId().toString());
                    if (examDetail.size()==0) {
                        return authInfo.set("error_description", "当前没有查询到考试信息");
                    }
                }
            }
        }
        return TokenUtil.createAuthInfo(userInfo);
    }
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -568,7 +568,7 @@
            from (
                select
                    distinct
                    bu.id
                    bu.id,
                    ifnull(TIMESTAMPDIFF(YEAR, SUBSTRING(bu.cardid, 7, 8), CURDATE()),0) AS age,
                    bu.is_apply isApply,
                    bu.is_train isTrain,