mirror of
https://github.com/capricornxl/ad-password-self-service.git
synced 2025-08-12 04:50:36 +08:00
### 本次升级、修复,请使用最新版:
+ 升级Python版本为3.8 + 升级Django到3.2 + 修复用户名中使用\被转义的问题 + 重写了dingding模块,因为dingding开发者平台接口鉴权的一些变动,之前的一些接口不能再使用,本次重写。 + 重写了ad模块,修改账号的一些判断逻辑。 + 重写了用户账号的格式兼容,现在用户账号可以兼容:username、DOMAIN\username、username@abc.com这三种格式。 + 优化了整体的代码逻辑,去掉一些冗余重复的代码。
This commit is contained in:
35
utils/format_username.py
Normal file
35
utils/format_username.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @FileName: format_username.py
|
||||
# @Software:
|
||||
# @Author: Leven Xiang
|
||||
# @Mail: xiangle0109@outlook.com
|
||||
# @Date: 2021/4/19 9:17
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def format2username(account):
|
||||
"""
|
||||
格式化账号,统一输出为用户名格式
|
||||
:param account 用户账号可以是邮箱、DOMAIN\\username、username格式。
|
||||
:return: username
|
||||
"""
|
||||
if account:
|
||||
mail_compile = re.compile(r'(.*)@(.*)')
|
||||
domain_compile = re.compile(r'(.*)\\(.*)')
|
||||
|
||||
if re.fullmatch(mail_compile, account):
|
||||
return re.fullmatch(mail_compile, account).group(1)
|
||||
elif re.fullmatch(domain_compile, account):
|
||||
return re.fullmatch(domain_compile, account).group(2)
|
||||
else:
|
||||
return account
|
||||
else:
|
||||
raise NameError("输入的账号不能为空..")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
user = 'aaa\jf.com'
|
||||
username = format2username(user)
|
||||
print(username)
|
Reference in New Issue
Block a user