mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
add ConstsRegex
This commit is contained in:
parent
0afd7790bc
commit
18f6f86b24
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.dromara.maxkey.constants;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex for email , mobile and etc.
|
||||||
|
*/
|
||||||
|
public class ConstsRegex {
|
||||||
|
|
||||||
|
public static final Pattern EMAIL_PATTERN = Pattern.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
|
||||||
|
|
||||||
|
public static final Pattern MOBILE_PATTERN = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$");
|
||||||
|
|
||||||
|
public static final Pattern IPADDRESS_REGEX = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
|
||||||
|
|
||||||
|
public static final Pattern WHITESPACE_REGEX = Pattern.compile("\\s");
|
||||||
|
|
||||||
|
public static final Pattern CHINESE_REGEX = Pattern.compile("[\\u4e00-\\u9fa5]");
|
||||||
|
}
|
||||||
@ -17,12 +17,11 @@
|
|||||||
|
|
||||||
package org.dromara.maxkey.web.contorller;
|
package org.dromara.maxkey.web.contorller;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dromara.maxkey.authn.jwt.AuthTokenService;
|
import org.dromara.maxkey.authn.jwt.AuthTokenService;
|
||||||
import org.dromara.maxkey.configuration.EmailConfig;
|
import org.dromara.maxkey.configuration.EmailConfig;
|
||||||
import org.dromara.maxkey.constants.ConstsEntryType;
|
import org.dromara.maxkey.constants.ConstsEntryType;
|
||||||
|
import org.dromara.maxkey.constants.ConstsRegex;
|
||||||
import org.dromara.maxkey.constants.ConstsAct;
|
import org.dromara.maxkey.constants.ConstsAct;
|
||||||
import org.dromara.maxkey.constants.ConstsActResult;
|
import org.dromara.maxkey.constants.ConstsActResult;
|
||||||
import org.dromara.maxkey.entity.ChangePassword;
|
import org.dromara.maxkey.entity.ChangePassword;
|
||||||
@ -47,10 +46,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
public class ForgotPasswordContorller {
|
public class ForgotPasswordContorller {
|
||||||
private static Logger logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
|
private static Logger logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
|
||||||
|
|
||||||
static final Pattern emailRegex = Pattern.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
|
|
||||||
|
|
||||||
static final Pattern mobileRegex = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$");
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EmailConfig emailConfig;
|
EmailConfig emailConfig;
|
||||||
|
|
||||||
@ -125,8 +120,8 @@ public class ForgotPasswordContorller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangePassword change = null;
|
ChangePassword change = null;
|
||||||
logger.debug("Mobile Regex matches {}",mobileRegex.matcher(mobile).matches());
|
logger.debug("Mobile Regex matches {}",ConstsRegex.MOBILE_PATTERN.matcher(mobile).matches());
|
||||||
if(StringUtils.isNotBlank(mobile) && mobileRegex.matcher(mobile).matches()) {
|
if(StringUtils.isNotBlank(mobile) && ConstsRegex.MOBILE_PATTERN.matcher(mobile).matches()) {
|
||||||
UserInfo userInfo = userInfoService.findByEmailMobile(mobile);
|
UserInfo userInfo = userInfoService.findByEmailMobile(mobile);
|
||||||
if(userInfo != null) {
|
if(userInfo != null) {
|
||||||
change = new ChangePassword(userInfo);
|
change = new ChangePassword(userInfo);
|
||||||
@ -152,7 +147,7 @@ public class ForgotPasswordContorller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangePassword change = null;
|
ChangePassword change = null;
|
||||||
if(StringUtils.isNotBlank(email) && emailRegex.matcher(email).matches()) {
|
if(StringUtils.isNotBlank(email) && ConstsRegex.EMAIL_PATTERN.matcher(email).matches()) {
|
||||||
UserInfo userInfo = userInfoService.findByEmailMobile(email);
|
UserInfo userInfo = userInfoService.findByEmailMobile(email);
|
||||||
if(userInfo != null) {
|
if(userInfo != null) {
|
||||||
change = new ChangePassword(userInfo);
|
change = new ChangePassword(userInfo);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user