wangwei 6 years ago
parent
commit
0f9f5c66bf

+ 15 - 8
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/enums/AccountType.java

@@ -12,25 +12,30 @@ public enum AccountType {
 	/**
 	 * 学生学号
 	 */
-	STUDENT_CODE("学生学号"),
+	STUDENT_CODE("SC", "学生学号"),
 
 	/**
 	 * 学生身份证号
 	 */
-	STUDENT_IDENTITY_NUMBER("学生身份证号"),
+	STUDENT_IDENTITY_NUMBER("SIN", "学生身份证号"),
 
 	/**
 	 * 学生手机号登录
 	 */
-	STUDENT_PHONE("学生手机号"),
+	STUDENT_PHONE("SP", "学生手机号"),
 
 	/**
 	 * 常规登录名(非学生登录)
 	 */
-	COMMON_LOGIN_NAME("常规登录名");
+	COMMON_LOGIN_NAME("C", "常规登录名");
 
 	// ===========================================================================
 
+	/**
+	 * 码
+	 */
+	private String code;
+
 	/**
 	 * 描述
 	 */
@@ -41,15 +46,17 @@ public enum AccountType {
 	 *
 	 * @param desc
 	 */
-	private AccountType(String desc) {
+	private AccountType(String code, String desc) {
+		this.code = code;
 		this.desc = desc;
 	}
 
-	/**
-	 * @return the desc
-	 */
 	public String getDesc() {
 		return desc;
 	}
 
+	public String getCode() {
+		return code;
+	}
+
 }

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

@@ -111,7 +111,7 @@ public class AuthServiceImpl implements AuthService {
 			throw new StatusException("B-001204", "accountType is wrong");
 		}
 
-		if (limited(accountType, accountValue, clientIp)) {
+		if (limited(accountTypeEnum, accountValue, clientIp)) {
 			throw new StatusException("B-001205", "密码重试次数已达到上限,请1分钟后重试");
 		}
 
@@ -162,7 +162,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			String rightPassword = userEntity.getPassword();
 			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountType, accountValue, clientIp);
+				whenPasswordError(accountTypeEnum, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 			user.setUserId(userEntity.getId());
@@ -191,7 +191,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			String rightPassword = student.getPassword();
 			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountType, accountValue, clientIp);
+				whenPasswordError(accountTypeEnum, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 
@@ -240,8 +240,8 @@ public class AuthServiceImpl implements AuthService {
 	 * @param accountValue
 	 * @param ip
 	 */
-	private void whenPasswordError(String accountType, String accountValue, String ip) {
-		String key = new StringBuilder("$_PW_ERR_").append(accountType).append("_")
+	private void whenPasswordError(AccountType accountType, String accountValue, String ip) {
+		String key = new StringBuilder("$_PW_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 
 		Integer times = redisClient.get(key, Integer.class);
@@ -263,8 +263,8 @@ public class AuthServiceImpl implements AuthService {
 	 * @param ip
 	 * @return
 	 */
-	private boolean limited(String accountType, String accountValue, String ip) {
-		String key = new StringBuilder("$_PW_ERR_").append(accountType).append("_")
+	private boolean limited(AccountType accountType, String accountValue, String ip) {
+		String key = new StringBuilder("$_PW_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 
 		Integer times = redisClient.get(key, Integer.class);