| | |
| | | import org.springblade.modules.loginrecord.entity.LoginRecord; |
| | | import org.springblade.modules.loginrecord.service.LoginRecordService; |
| | | import org.springblade.modules.system.entity.UserInfo; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springblade.modules.zc.service.IZcService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | |
| | | private final LoginRecordService loginRecordService; |
| | | |
| | | private final ServerConfig serverConfig; |
| | | private final IUserService userService; |
| | | |
| | | /** |
| | | * 登录 |
| | |
| | | ITokenGranter granter = TokenGranterBuilder.getGranter(grantType); |
| | | UserInfo userInfo = granter.grant(tokenParameter); |
| | | |
| | | try { |
| | | Long parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-09-11").getTime(); |
| | | long now= System.currentTimeMillis(); |
| | | if (parse < now){ |
| | | throw new ServiceException("试用已到期"); |
| | | } |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // try { |
| | | // Long parse = new SimpleDateFormat("yyyy-MM-dd").parse("2024-12-30").getTime(); |
| | | // long now= System.currentTimeMillis(); |
| | | // if (parse < now){ |
| | | // throw new ServiceException("系统繁忙"); |
| | | // } |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | |
| | | //校验 |
| | |
| | | return authInfo.set("error_description", "审核不通过"); |
| | | } |
| | | } |
| | | if (userInfo != null && userInfo.getUser().getIsFreeze().equals(1)) { |
| | | return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "该用户超半年未使用系统,已被冻结,请联系管理员!"); |
| | | } |
| | | |
| | | if (userInfo == null || userInfo.getUser() == null) { |
| | | return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户名或密码不正确"); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | System.out.println("grantType = " + grantType); |
| | | //如果是app模拟考试登录 |
| | | if (loginType.equals(2)) { |
| | | //判断是否已报名 |
| | | boolean flag = userService.getUserIsApply(userInfo.getUser().getId()); |
| | | if (!flag){ |
| | | return authInfo.set("error_description", "没有报名不能进行刷题"); |
| | | } |
| | | } |
| | | //刷新 token 不新增登录记录 |
| | | // if (!grantType.equals("refresh_token")){ |
| | | // //新增登录记录 |
| | | // this.saveLoginRecord(userInfo); |
| | | // } |
| | | if (!grantType.equals("refresh_token")){ |
| | | //新增登录记录 |
| | | this.saveLoginRecord(userInfo); |
| | | } |
| | | }else { |
| | | //刷新 token 不新增登录记录 |
| | | if (!grantType.equals("refresh_token")){ |
| | | //新增登录记录 |
| | | this.saveLoginRecord(userInfo); |
| | | } |
| | | } |
| | | return TokenUtil.createAuthInfo(userInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 微信小程序账号登录 |
| | | * @param tenantId |
| | | * @param username |
| | | * @param password |
| | | * @return |
| | | */ |
| | | @ApiLog("登录用户验证") |
| | | @PostMapping("/oauth/token/wxAccount") |
| | | @ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password,登录类型:loginType") |
| | | public Kv wxAccount(@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) { |
| | | |
| | | Kv authInfo = Kv.create(); |
| | | |
| | | String grantType = WebUtil.getRequest().getParameter("grant_type"); |
| | | String refreshToken = WebUtil.getRequest().getParameter("refresh_token"); |
| | | |
| | | String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.USER_TYPE_WX); |
| | | |
| | | TokenParameter tokenParameter = new TokenParameter(); |
| | | tokenParameter.getArgs().set("tenantId", tenantId).set("username", username).set("password", password).set("grantType", grantType).set("refreshToken", refreshToken).set("userType", userType); |
| | | |
| | | ITokenGranter granter = TokenGranterBuilder.getGranter(grantType); |
| | | |
| | | // try { |
| | | // Long parse = new SimpleDateFormat("yyyy-MM-dd").parse("2024-12-30").getTime(); |
| | | // long now= System.currentTimeMillis(); |
| | | // if (parse < now){ |
| | | // throw new ServiceException("系统繁忙"); |
| | | // } |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | |
| | | UserInfo userInfo = granter.grant(tokenParameter); |
| | | |
| | | if (userInfo == null || userInfo.getUser() == null) { |
| | | return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户名或密码不正确"); |
| | | } |
| | | |
| | | return TokenUtil.createAuthInfo(userInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | 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 code) { |
| | | |
| | | Kv authInfo = Kv.create(); |
| | | String s = iZcService.selectType(username); |
| | | |
| | | String grantType = WebUtil.getRequest().getParameter("grant_type"); |
| | | String refreshToken = WebUtil.getRequest().getParameter("refresh_token"); |
| | |
| | | |
| | | ITokenGranter granter = TokenGranterBuilder.getGranter(grantType); |
| | | UserInfo userInfo = granter.grant(tokenParameter); |
| | | |
| | | try { |
| | | Long parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-08-08").getTime(); |
| | | long now= System.currentTimeMillis(); |
| | | if (parse < now){ |
| | | throw new ServiceException("试用已到期"); |
| | | } |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | //校验 |
| | | if (null != s && s.equals("")) { |
| | | if (s.equals("0")) { |
| | | return authInfo.set("error_description", "用户未审核"); |
| | | } |
| | | if (s.equals("2")) { |
| | | return authInfo.set("error_description", "审核不通过"); |
| | | } |
| | | } |
| | | if (userInfo == null || userInfo.getUser() == null) { |
| | | return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户不存在"); |
| | | } |
| | | |
| | | return TokenUtil.createAuthInfo(userInfo); |
| | | } |