Browse Source

手机app适配:手机登录忽略验证码校验

ZhuJiaHao 2 months ago
parent
commit
b698a2c838

+ 10 - 0
ibps-oauth-root/modules/oauth-core/src/main/java/com/lc/ibps/cloud/oauth/entity/LoginVo.java

@@ -37,6 +37,8 @@ public class LoginVo implements Serializable {
 	private String orgCode;
 	@ApiModelProperty(value = "第三方接入token")
 	private String token;
+	@ApiModelProperty(value = "客户端类型:mobile-移动端(不需要验证码),其他值或不传则按原有机制")
+	private String clientType;
 	
 	public LoginVo() {
 		super();
@@ -130,4 +132,12 @@ public class LoginVo implements Serializable {
 	public void setToken(String token) {
 		this.token = token;
 	}
+
+	public String getClientType() {
+		return clientType;
+	}
+
+	public void setClientType(String clientType) {
+		this.clientType = clientType;
+	}
 }

+ 10 - 3
ibps-oauth-root/modules/oauth-server2-default/src/main/java/com/lc/ibps/cloud/oauth/server/provider/UserProvider.java

@@ -156,7 +156,7 @@ public class UserProvider extends BaseProvider implements IUserService {
 				}
 			}else{
 				// 验证码校验
-				captcha(requestId, username, captcha);
+				captcha(requestId, username, captcha, loginVo.getClientType());
 				// 用户登录
 				try{
 					String password = AESUtil.decryptUser(loginVo.getPassword());
@@ -341,9 +341,16 @@ public class UserProvider extends BaseProvider implements IUserService {
 	 *
 	 * @param requestId
 	 * @param account
-	 * @param captcha 
+	 * @param captcha
+	 * @param clientType 客户端类型,mobile时跳过验证码
 	 */
-	private void captcha(String requestId, String account, String captcha) {
+	private void captcha(String requestId, String account, String captcha, String clientType) {
+		// 移动端跳过验证码校验
+		if("mobile".equalsIgnoreCase(clientType)) {
+			logger.debug("Mobile client login, skip captcha validation.");
+			return;
+		}
+		
 		String captchaKey = appConfig.getRedisKey(RedisKey.LOGIN_CAPTCHA, RequestUtil.getIpAddr(RequestContext.getHttpServletRequest()));
 		String userCaptcha = RedisUtil.redisTemplateString.opsForValue().get(captchaKey);
 		if(userConfig.getCaptcha().isEnabled() || (userConfig.getCaptcha().isForceEnabled() && StringUtil.isNotBlank(userCaptcha)))