Prechádzať zdrojové kódy

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

Eric 2 mesiacov pred
rodič
commit
806630e24e

+ 7 - 6
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/provider/PhoneAuthenticationProvider.java

@@ -143,15 +143,16 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
                 }
 
             } else {
+                // 验证码验证
+                boolean b = smsCodeService.verifyValidCode(phone, smsCode, "SMS_VERIFY_CODE_LOGIN");
+                if (!b) {
+                    throw new BadCredentialsException("验证码校验失败");
+                }
+
+                // 老师扫码登陆
                 if (loginEntity.getClientId().toLowerCase().startsWith("qr_")) {
                     // 重置登录账号信息
                     loginEntity.setClientId(loginEntity.getClientId().toLowerCase().replace("qr_", "").toUpperCase());
-                } else {
-                    // 验证码验证
-                    boolean b = smsCodeService.verifyValidCode(phone, smsCode, "SMS_VERIFY_CODE_LOGIN");
-                    if (!b) {
-                        throw new BadCredentialsException("验证码校验失败");
-                    }
                 }
             }
 

+ 1 - 1
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/provider/service/DefaultUserDetailsService.java

@@ -79,7 +79,7 @@ public class DefaultUserDetailsService implements UserDetailsService {
             if (UserLockFlag.LOCKED.equals(data.getLockFlag())) {
                 throw new LockedException("账户被锁定");
             }
-        }else if(SysUserType.TEACHER.getCode().equals(clientId)) {
+        }else if(SysUserType.TEACHER.getCode().equals(clientId) || "qr_teacher".equalsIgnoreCase(clientId)) {
             TeacherApi data = adminFeignService.getTeacher(sysUser.getId()).getData();
             if (data == null) {
                 throw new UsernameNotFoundException("账户不存在");

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

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.auth.service.impl;
 
+import cn.hutool.core.util.RandomUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.dayaedu.cbs.openfeign.wrapper.qrcode.CbsQrCodeScanWrapper;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
@@ -8,15 +9,16 @@ import com.yonge.cooleshow.auth.core.service.CustomTokenServices;
 import com.yonge.cooleshow.auth.dal.dao.SysConfigDao;
 import com.yonge.cooleshow.auth.service.SysUserService;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.cooleshow.common.service.IdGeneratorService;
 import com.yonge.toolset.base.exception.BizException;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.Map;
-import java.util.UUID;
 
 @Service
 public class CbsQrCodeScanServiceImpl {
@@ -30,10 +32,23 @@ public class CbsQrCodeScanServiceImpl {
     @Resource
     private SysConfigDao sysConfigDao;
 
+    @Autowired
+    private IdGeneratorService smsCodeService;
+
     public CbsQrCodeScanWrapper.UserInfo userInfo(CbsQrCodeScanWrapper.QrCodeScanUserInfoReq req) {
         CbsQrCodeScanWrapper.UserInfo userInfo = new CbsQrCodeScanWrapper.UserInfo();
         userInfo.setUsername(customTokenServices.loadAuthentication(req.getToken()).getName().split(":")[1]);
         userInfo.setClientTypes("TEACHER");
+
+        SysUser sysUser = sysUserService.queryByPhone(userInfo.getUsername());
+        if (sysUser == null) {
+            throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
+        }
+
+        if (sysUser.getTenantId() == -1L) {
+            // 平台老师不允许扫码登录乐教通,返回机构ID
+            userInfo.setClientTypes("-1");
+        }
         return userInfo;
     }
 
@@ -51,8 +66,12 @@ public class CbsQrCodeScanServiceImpl {
             throw new BizException("扫码登陆失败: 用户已锁定");
         }
 
+        // 生成6位随机数验证码
+        String code = RandomUtil.randomNumbers(6);
+        // 保存验证码
+        smsCodeService.saveVerifyValidCode(phone, code, "SMS_VERIFY_CODE_LOGIN");
         //调用登陆接口
-        HttpResponseResult<Map<String,Object>> result = sysUserFeignService.smsLogin(phone, UUID.randomUUID().toString(),"SMS", req.getClientId(), req.getClientSecret());
+        HttpResponseResult<Map<String,Object>> result = sysUserFeignService.smsLogin(phone, code,"SMS", req.getClientId(), req.getClientSecret());
         if (result != null){
             if(result.getCode() != 200){
                 throw new BizException("扫码登陆失败", result.getMsg());

+ 7 - 1
cooleshow-common/src/main/java/com/yonge/cooleshow/common/service/IdGeneratorService.java

@@ -23,5 +23,11 @@ public interface IdGeneratorService {
 	 */
 	boolean verifyValidCode(String mobile, String authCode,String keyEnum);
 
-
+	/**
+	 * 保存验证码
+	 * @param mobile 手机号
+	 * @param authCode 验证码
+	 * @param keyEnum 验证码类型
+	 */
+	void saveVerifyValidCode(String mobile, String authCode,String keyEnum);
 }

+ 13 - 0
cooleshow-common/src/main/java/com/yonge/cooleshow/common/service/impl/RedisIdGeneratorService.java

@@ -115,6 +115,19 @@ public class RedisIdGeneratorService implements IdGeneratorService {
 		return false;
 	}
 
+	/**
+	 * 保存验证码
+	 *
+	 * @param mobile   手机号
+	 * @param authCode 验证码
+	 * @param keyEnum  验证码类型
+	 */
+	@Override
+	public void saveVerifyValidCode(String mobile, String authCode, String keyEnum) {
+		String key = "verificationCode" + keyEnum + mobile;
+		// 验证码有效性:10分钟
+		redisCache.put(key, authCode, 600);
+	}
 
 
 }