Skip to content

Commit

Permalink
perf: 优化三方登录创建的用户邮箱会校验,非法邮箱会重置成默认格式
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Mar 11, 2024
1 parent 86d76c5 commit 60e4b19
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions apps/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,24 @@ class LoginIpBlockUtil(BlockGlobalIpUtilBase):
BLOCK_KEY_TMPL = "_LOGIN_BLOCK_{}"


def validate_email(addr):
addr = addr or ''
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if re.match(pattern, addr):
return addr
else:
return ''


def construct_user_email(username, email, email_suffix=''):
if email is None:
email = ''
if '@' in email:
return email
if '@' in username:
return username
if not email_suffix:
email_suffix = settings.EMAIL_SUFFIX
email = f'{username}@{email_suffix}'
email_suffix = email_suffix or settings.EMAIL_SUFFIX

email = validate_email(email)
if not email:
email = validate_email(username)

if not email:
email = f'{username}@{email_suffix}'
return email


Expand Down

0 comments on commit 60e4b19

Please sign in to comment.