perf: 优化邮箱校验逻辑

pull/12795/head^2
Bai 2024-03-11 18:40:57 +08:00 committed by Bryan
parent afe3777895
commit d0117b5a91
1 changed files with 9 additions and 14 deletions

View File

@ -230,24 +230,19 @@ class LoginIpBlockUtil(BlockGlobalIpUtilBase):
BLOCK_KEY_TMPL = "_LOGIN_BLOCK_{}" BLOCK_KEY_TMPL = "_LOGIN_BLOCK_{}"
def validate_email(addr): def validate_emails(emails):
addr = addr or ''
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if re.match(pattern, addr): for e in emails:
return addr e = e or ''
else: if re.match(pattern, e):
return '' return e
def construct_user_email(username, email, email_suffix=''): def construct_user_email(username, email, email_suffix=''):
email = validate_email(email) default = f'{username}@{email_suffix or settings.EMAIL_SUFFIX}'
if not email: emails = [email, username]
email = validate_email(username) email = validate_emails(emails)
return email or default
if not email:
email_suffix = email_suffix or settings.EMAIL_SUFFIX
email = f'{username}@{email_suffix}'
return email
def get_current_org_members(): def get_current_org_members():