| | |
| | | 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.*; |
| | |
| | | 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); |
| | |
| | | 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", "用户未审核"); |
| | | } |
| | |
| | | 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", "用户名或密码不正确"); |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | |