| | |
| | | */ |
| | | @PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE)//前端提交json数据 |
| | | public BaseResponse<UserVo> login(@RequestBody @Valid LoginVo vo, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | try { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | return this.doLogin(vo) ; |
| | | } catch (Exception e) { |
| | | log.error("查询一个用户数据异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | return this.doLogin(vo) ; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)//前端提交form表单数据 |
| | | public BaseResponse<UserVo> loginForm(@RequestBody @Valid LoginVo vo, BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | try{ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | return this.doLogin(vo) ; |
| | | } catch (Exception e) { |
| | | log.error("查询一个用户数据异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | return this.doLogin(vo) ; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @GetMapping(path = "logout") |
| | | public BaseResponse<Boolean> logout(HttpServletRequest hr){ |
| | | String token = hr.getHeader("token") ; |
| | | if(token != null){ |
| | | this.sv.logout(token) ; |
| | | return BaseResponseUtils.buildSuccess(true); |
| | | }else{ |
| | | return BaseResponseUtils.buildFail("未从header中得到token"); |
| | | try{ |
| | | String token = hr.getHeader("token") ; |
| | | if(token != null){ |
| | | this.sv.logout(token) ; |
| | | return BaseResponseUtils.buildSuccess(true); |
| | | }else{ |
| | | return BaseResponseUtils.buildFail("未从header中得到token"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("查询一个用户数据异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |