Browse Source

Merge branch 'feature/0902-scan-qrcode' into develop-new

Eric 2 months ago
parent
commit
a929eb82fd

+ 8 - 1
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/service/CustomAuthenticationKeyGenerator.java

@@ -4,6 +4,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeSet;
 
+import cn.hutool.core.util.RandomUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.oauth2.common.util.OAuth2Utils;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
@@ -25,7 +26,13 @@ public class CustomAuthenticationKeyGenerator extends DefaultAuthenticationKeyGe
 		if (!authentication.isClientOnly()) {
 			values.put(USERNAME, StringUtils.substringAfter(authentication.getName(), ":"));
 		}
-		values.put(CLIENT_ID, authorizationRequest.getClientId());
+
+		String clientId = authorizationRequest.getClientId();
+		if (StringUtils.isNotEmpty(clientId) && "qr_teacher".equalsIgnoreCase(clientId)) {
+			// 酷乐秀老师端扫码登录,允许多端登录,同时生成多个token
+			clientId += ":" + RandomUtil.randomNumbers(6);
+		}
+		values.put(CLIENT_ID, clientId);
 		if (authorizationRequest.getScope() != null) {
 			values.put(SCOPE, OAuth2Utils.formatParameterList(new TreeSet<String>(authorizationRequest.getScope())));
 		}

+ 4 - 2
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/service/impl/CbsQrCodeScanServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.Map;
+import java.util.Objects;
 
 @Service
 public class CbsQrCodeScanServiceImpl {
@@ -44,8 +45,9 @@ public class CbsQrCodeScanServiceImpl {
         if (sysUser == null) {
             throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
         }
-
-        if (sysUser.getTenantId() == -1L) {
+        // 查询老师机构ID
+        Long tenantId = sysUserService.getTenantByClient(sysUser.getId(), "TEACHER");
+        if (Objects.nonNull(tenantId) && tenantId == -1L) {
             // 平台老师不允许扫码登录乐教通,返回机构ID
             userInfo.setClientTypes("-1");
         }