Add maskEmail(), fix Safari bug.

This commit is contained in:
Yang Luo 2021-06-25 21:35:20 +08:00
parent 234a9b9060
commit 2ba44748c2
3 changed files with 33 additions and 7 deletions

View File

@ -22,7 +22,8 @@ import (
var rePhoneCn *regexp.Regexp
func init() {
rePhoneCn, _ = regexp.Compile("^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|191|198|199|(147))\\d{8}$")
// https://learnku.com/articles/31543
rePhoneCn, _ = regexp.Compile("^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$")
}
func IsEmailValid(email string) bool {

View File

@ -27,10 +27,10 @@ export let ServerUrl = "";
// export const StaticBaseUrl = "https://cdn.jsdelivr.net/gh/casbin/static";
export const StaticBaseUrl = "https://cdn.casbin.org";
// reference link: https://github.com/yiminghe/async-validator/blob/057b0b047f88fac65457bae691d6cb7c6fe48ce1/src/rule/type.ts#L9
export const EmailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
// https://github.com/yiminghe/async-validator/blob/057b0b047f88fac65457bae691d6cb7c6fe48ce1/src/rule/type.ts#L9
export const EmailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
// reference link: https://learnku.com/articles/31543, `^s*$` filter empty email individually.
// https://learnku.com/articles/31543, `^s*$` filter empty email individually.
export const PhoneRegEx = /^\s*$|^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
export function initServerUrl() {
@ -420,3 +420,30 @@ export function getLabel(text, tooltip) {
</React.Fragment>
);
}
function repeat(str, len) {
while (str.length < len) {
str += str.substr(0, len - str.length);
}
return str;
}
function maskString(s) {
if (s.length <= 2) {
return s;
} else {
return `${s[0]}${repeat("*", s.length - 2)}${s[s.length - 1]}`;
}
}
export function maskEmail(email) {
const tokens = email.split("@");
let username = tokens[0];
username = maskString(username);
const domain = tokens[1];
let domainTokens = domain.split(".");
domainTokens[domainTokens.length - 2] = maskString(domainTokens[domainTokens.length - 2]);
return `${username}@${domainTokens.join(".")}`;
}

View File

@ -298,9 +298,7 @@ class ForgetPage extends React.Component {
{this.state.phone.replace(/(\d{3})\d*(\d{4})/,'$1****$2')}
</Option>
<Option key={2} value={this.state.email}>
{this.state.email.split("@")[0].length>2?
this.state.email.replace(/(?<=.)[^@]+(?=.@)/, "*****"):
this.state.email.replace(/(\w?@)/, "*@")}
{Setting.maskEmail(this.state.email)}
</Option>
</Select>
}