WANG 6 жил өмнө
parent
commit
c45f008909

+ 13 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/LoginInfo.java

@@ -37,6 +37,11 @@ public class LoginInfo implements JsonSerializable {
 	 */
 	private String password;
 
+	/**
+	 * 短信验证码
+	 */
+	private String smsCode;
+
 	/**
 	 * 客户端IP
 	 */
@@ -103,4 +108,12 @@ public class LoginInfo implements JsonSerializable {
 		this.alwaysOK = alwaysOK;
 	}
 
+	public String getSmsCode() {
+		return smsCode;
+	}
+
+	public void setSmsCode(String smsCode) {
+		this.smsCode = smsCode;
+	}
+
 }

+ 26 - 4
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -47,6 +47,9 @@ import cn.com.qmth.examcloud.core.basic.service.AuthService;
 import cn.com.qmth.examcloud.core.basic.service.SysConfigService;
 import cn.com.qmth.examcloud.core.basic.service.UserService;
 import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
+import cn.com.qmth.examcloud.exchange.inner.api.SendSmsCloudService;
+import cn.com.qmth.examcloud.exchange.inner.api.request.CheckSmsCodeReq;
+import cn.com.qmth.examcloud.exchange.inner.api.response.CheckIdentifyingCodeResp;
 
 /**
  * 类注释
@@ -91,6 +94,9 @@ public class AuthServiceImpl implements AuthService {
 	@Autowired
 	SysConfigService sysConfigService;
 
+	@Autowired
+	SendSmsCloudService sendSmsCloudService;
+
 	@Override
 	public User login(LoginInfo loginInfo) {
 
@@ -98,6 +104,7 @@ public class AuthServiceImpl implements AuthService {
 		String accountValue = loginInfo.getAccountValue();
 		String password = loginInfo.getPassword();
 		String clientIp = loginInfo.getClientIp();
+		String smsCode = loginInfo.getSmsCode();
 
 		if (StringUtils.isBlank(accountType)) {
 			throw new StatusException("B-001201", "accountType is null");
@@ -216,10 +223,25 @@ public class AuthServiceImpl implements AuthService {
 			if (null != student.getEnable() && !student.getEnable()) {
 				throw new StatusException("B-001005", "账户被禁用");
 			}
-			String rightPassword = student.getPassword();
-			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountTypeEnum, accountValue, clientIp);
-				throw new StatusException("B-001003", "账号或密码错误");
+
+			// 验证码登录
+			if (AccountType.STUDENT_PHONE.equals(accountTypeEnum)
+					&& StringUtils.isNotBlank(smsCode)) {
+				CheckSmsCodeReq req = new CheckSmsCodeReq();
+				req.setCode(smsCode);
+				req.setPhone(accountValue);
+				CheckIdentifyingCodeResp resp = sendSmsCloudService.checkIdentifyingCode(req);
+				if (!resp.getSuccess()) {
+					throw new StatusException("B-001050", "验证码错误");
+				}
+			}
+			// 密码登录
+			else {
+				String rightPassword = student.getPassword();
+				if (!rightPassword.equals(password)) {
+					whenPasswordError(accountTypeEnum, accountValue, clientIp);
+					throw new StatusException("B-001003", "账号或密码错误");
+				}
 			}
 
 			user.setUserId(student.getId());