liurunyu
2024-04-24 e430bfca38cdae9dd230f951e108a75caebccb61
pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -4,6 +4,7 @@
import com.dy.common.util.MD5;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pmsGlobal.aop.Log;
import com.dy.pmsGlobal.pojoBa.BaUser;
import com.mysql.cj.util.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
@@ -45,11 +46,17 @@
     * @return 登录用户值对象
     */
    @PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE)//前端提交json数据
    @Log("用户登录(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) ;
    }
    /**
@@ -58,11 +65,17 @@
     * @return 登录用户值对象
     */
    @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)//前端提交form表单数据
    @Log("用户登录(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) ;
    }
@@ -72,13 +85,19 @@
     * @return 正常退出登录返回true,否则返回false
     */
    @GetMapping(path = "logout")
    @Log("退出登录")
    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());
        }
    }