|  |  |  | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.UUID; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 注解Tag 在API中显示: Tag 注解, 给整个接口起了个名字与描述" | 
|---|
|  |  |  | 
|---|
|  |  |  | //在属性上注解@Autowired时,会警告 Field injection is not recommended(不再推荐使用字段注入) | 
|---|
|  |  |  | private SsoSv sv ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //private KaptchaConfig kaptchaConfig; | 
|---|
|  |  |  | //@Autowired | 
|---|
|  |  |  | //private CacheManager cacheManager ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.sv = sv ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //@Autowired | 
|---|
|  |  |  | //public void setKaptchaConfig(KaptchaConfig kaptchaConfig) { | 
|---|
|  |  |  | //    this.kaptchaConfig = kaptchaConfig; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到所有组织机构 | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) { | 
|---|
|  |  |  | public BaseResponse<UserVo> loginJson(HttpServletRequest request, @RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo,  @Parameter(hidden = true) BindingResult bindingResult) { | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //把组织单位标签作为数据源名称 | 
|---|
|  |  |  | DataSourceContext.set(vo.orgTag); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String token = Optional.ofNullable(vo.getToken()).orElse(""); | 
|---|
|  |  |  | String code = Optional.ofNullable(vo.getCode()).orElse(""); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(token.length() > 0 && code.length() > 0) { | 
|---|
|  |  |  | // 从session中获取验证码 | 
|---|
|  |  |  | //HttpSession session = (HttpSession) request.getSession(); | 
|---|
|  |  |  | //String localCode = session.getAttribute(token).toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map map = sv.getCodeByToken(token); | 
|---|
|  |  |  | Long expiration = Long.parseLong(map.get("expiration").toString()); | 
|---|
|  |  |  | Long currentTimestamp = System.currentTimeMillis(); | 
|---|
|  |  |  | if(currentTimestamp > expiration) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("验证码已超时"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 从数据库获取验证码 | 
|---|
|  |  |  | String localCode = map.get("code").toString(); | 
|---|
|  |  |  | if(!code.equals(localCode)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("验证码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //得到所有用户账号 | 
|---|
|  |  |  | List<String> phones = sv.getPhones(); | 
|---|
|  |  |  | if(!phones.contains(vo.phone)){ | 
|---|