mirror of https://github.com/jumpserver/jumpserver
perf: 优化三方登录创建的用户邮箱会校验,非法邮箱会重置成默认格式
parent
86d76c53d6
commit
60e4b19d07
|
@ -230,16 +230,24 @@ class LoginIpBlockUtil(BlockGlobalIpUtilBase):
|
||||||
BLOCK_KEY_TMPL = "_LOGIN_BLOCK_{}"
|
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=''):
|
def construct_user_email(username, email, email_suffix=''):
|
||||||
if email is None:
|
email_suffix = email_suffix or settings.EMAIL_SUFFIX
|
||||||
email = ''
|
|
||||||
if '@' in email:
|
email = validate_email(email)
|
||||||
return email
|
if not email:
|
||||||
if '@' in username:
|
email = validate_email(username)
|
||||||
return username
|
|
||||||
if not email_suffix:
|
if not email:
|
||||||
email_suffix = settings.EMAIL_SUFFIX
|
email = f'{username}@{email_suffix}'
|
||||||
email = f'{username}@{email_suffix}'
|
|
||||||
return email
|
return email
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue