|
@@ -3,6 +3,7 @@ package com.github.zuihou.oauth.controller;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.github.zuihou.authority.dto.auth.LoginParamDTO;
|
|
|
import com.github.zuihou.base.R;
|
|
|
+import com.github.zuihou.common.constant.BizConstant;
|
|
|
import com.github.zuihou.context.BaseContextHandler;
|
|
|
import com.github.zuihou.exception.BizException;
|
|
|
import com.github.zuihou.jwt.TokenUtil;
|
|
@@ -16,6 +17,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -23,6 +25,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
+import static com.github.zuihou.utils.BizAssert.isFalse;
|
|
|
+
|
|
|
/**
|
|
|
* 认证Controller
|
|
|
*
|
|
@@ -116,4 +120,32 @@ public class OauthController {
|
|
|
}
|
|
|
return authManager.adminLogin(login.getAccount(), login.getPassword());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 二维码登录系统
|
|
|
+ *
|
|
|
+ * @param login
|
|
|
+ * @return
|
|
|
+ * @throws BizException
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "二维码登录", notes = "登录或者清空缓存时调用")
|
|
|
+ @PostMapping(value = "/qcodelogin")
|
|
|
+ public R<AuthInfo> qcodelogin(@Validated @RequestBody LoginParamDTO login) throws BizException {
|
|
|
+ if (StrUtil.isBlank(login.getTenant())) {
|
|
|
+ login.setTenant(BaseContextHandler.getTenant());
|
|
|
+ }
|
|
|
+ login.setTenant(JwtUtil.base64Decoder(login.getTenant()));
|
|
|
+ if(StringUtils.isNotBlank(login.getQcodeUser())){
|
|
|
+ String[] tokenUserInfos = login.getQcodeUser().split("-");
|
|
|
+ isFalse(tokenUserInfos.length != 3, "扫码用户参数错误");
|
|
|
+ login.setAccount(tokenUserInfos[0]);
|
|
|
+ login.setPassword(tokenUserInfos[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ TokenGranter granter = tokenGranterBuilder.getGranter(login.getGrantType());
|
|
|
+ R<AuthInfo> userInfo = granter.grant(login);
|
|
|
+
|
|
|
+ return userInfo;
|
|
|
+ }
|
|
|
}
|