Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
9d7ffbce
Commit
9d7ffbce
authored
Jun 19, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
srv tip add mutil lang 2024-06-19
parent
e8e4ca77
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
253 additions
and
41 deletions
+253
-41
constants.py
unify_api/constants.py
+145
-2
multi_lang.py
unify_api/modules/common/procedures/multi_lang.py
+13
-1
login_pds.py
unify_api/modules/users/procedures/login_pds.py
+24
-11
current_user_info.py
unify_api/modules/users/views/current_user_info.py
+71
-27
No files found.
unify_api/constants.py
View file @
9d7ffbce
...
@@ -747,6 +747,64 @@ PHASE_LINE_LANG = {
...
@@ -747,6 +747,64 @@ PHASE_LINE_LANG = {
},
},
}
}
PRODUCT_NAME
=
{
1
:
{
"zh_CN"
:
"知电U+"
,
"en_US"
:
"Master Electricity Use U+"
,
"de_DE"
:
"ZhiDian U+"
},
2
:
{
"zh_CN"
:
"安电U+"
,
"en_US"
:
"Safe Electricity Use U+"
,
"de_DE"
:
"Andean U+"
},
3
:
{
"zh_CN"
:
"安电U+——管理版"
,
"en_US"
:
"Safe Electricity Use U+ —— Management Edition"
,
"de_DE"
:
"Andean U+ Management-Version"
},
4
:
{
"zh_CN"
:
"识电U+"
,
"en_US"
:
"Recognize Electricity Use U+"
,
"de_DE"
:
"ShiDian U+"
},
5
:
{
"zh_CN"
:
"知电U+——管理版"
,
"en_US"
:
"Master Electricity Use U+ —— Management Edition"
,
"de_DE"
:
"ZhiDian U+ Management-Version"
},
6
:
{
"zh_CN"
:
"智电U+"
,
"en_US"
:
"Smart Electricity Use U+"
,
"de_DE"
:
"ZhiDian U+"
},
7
:
{
"zh_CN"
:
"综合能源低碳数字化园区指挥管理平台"
,
"en_US"
:
"Integrated Energy Low-Carbon Digital Park Command and Management Platform"
,
"de_DE"
:
"Integrierte Energie-Niederigkohlenstoff-Digitalpark-Management-Plattform"
},
8
:
{
"zh_CN"
:
"扬尘生态环境管理"
,
"en_US"
:
"Dust Control Environmental Management"
,
"de_DE"
:
"Staub- und Ökomanagement"
},
10
:
{
"zh_CN"
:
"智维U+"
,
"en_US"
:
"Smart Operation and Maintenance U+"
,
"de_DE"
:
"ZhiWei U+"
},
12
:
{
"zh_CN"
:
"安识U+"
,
"en_US"
:
"Safety Identification U+"
,
"de_DE"
:
"AnShi U+"
},
13
:
{
"zh_CN"
:
"清科优能官方网站管理平台"
,
"en_US"
:
"Amber Optimal Official Website Management Platform"
,
"de_DE"
:
"offizielle Webseit-Management-Plattform von Qingke"
}
}
LOG_IN_TIPS
=
{
LOG_IN_TIPS
=
{
"err_uname_pwd"
:
{
"err_uname_pwd"
:
{
"zh_CN"
:
"用户名或密码错误"
,
"zh_CN"
:
"用户名或密码错误"
,
...
@@ -756,11 +814,96 @@ LOG_IN_TIPS = {
...
@@ -756,11 +814,96 @@ LOG_IN_TIPS = {
"err_vfy_code"
:
{
"err_vfy_code"
:
{
"zh_CN"
:
"验证码错误"
,
"zh_CN"
:
"验证码错误"
,
"en_US"
:
"Verification code is incorrect"
,
"en_US"
:
"Verification code is incorrect"
,
"de_DE"
:
"
Diese Telefonnummer is bereits verknüpft
"
"de_DE"
:
"
Bestätigungscode ist falsch
"
},
},
"phone_bound"
:
{
"phone_bound"
:
{
"zh_CN"
:
"该手机号已被绑定"
,
"zh_CN"
:
"该手机号已被绑定"
,
"en_US"
:
"This phone number has already been bound"
,
"en_US"
:
"This phone number has already been bound"
,
"de_DE"
:
""
"de_DE"
:
"Diese Telefonnummer is bereits verknüpft"
},
"err_phone_fmt"
:
{
"zh_CN"
:
"手机号码格式错误"
,
"en_US"
:
"The phone number format is incorrect"
,
"de_DE"
:
"Ungültiges Format der Telefonnummer"
},
"vfy_code_inconst"
:
{
"zh_CN"
:
"验证码不一致"
,
"en_US"
:
"The verification code is inconsistent"
,
"de_DE"
:
"Bestätigungscode stimmt nicht überein"
},
"send_suc"
:
{
"zh_CN"
:
"发送成功"
,
"en_US"
:
"Sending successful"
,
"de_DE"
:
"Erfolgreic gesendet"
},
"msg_send_lim"
:
{
"zh_CN"
:
"您今日发送短信次数已用完"
,
"en_US"
:
"Your daily limit for sending text messages has been reached"
,
"de_DE"
:
"Sie haben das täglich SMS- Limit erreicht "
},
"vfy_code_freq"
:
{
"zh_CN"
:
"请求验证码过于频繁"
,
"en_US"
:
"The request for a verification code is too frequent."
,
"de_DE"
:
"Bestätigungscode zu oft angefordert"
},
"vfy_code_freq_hr"
:
{
"zh_CN"
:
"请求验证码过于频繁,请1小时后重新发送"
,
"en_US"
:
"Please wait for an hour before requesting the verification code again due to excessive requests"
,
"de_DE"
:
"Bestätigungscode zu oft angefordert, bitte nach 1 Stunde erneut senden"
},
"vfy_code_freq_min"
:
{
"zh_CN"
:
"请求验证码过于频繁,请1分钟后重新发送"
,
"en_US"
:
"Please wait for 1 minute before requesting the verification code again due to the high frequency of requests"
,
"de_DE"
:
"Bestätigungscode zu oft angefordert, bitte nach 1 Minute erneut senden"
},
"vfy_code_send_fail"
:
{
"zh_CN"
:
"验证码发送失败"
,
"en_US"
:
"The verification code failed to send"
,
"de_DE"
:
"Senden des Bestätigungscode fehlgeschlagen"
},
"phone_not_invalid"
:
{
"zh_CN"
:
"手机号码不合法"
,
"en_US"
:
"The phone number is invalid"
,
"de_DE"
:
"Ungünstige Telefonnummer"
},
"passwd_inconst"
:
{
"zh_CN"
:
"两次密码不一致"
,
"en_US"
:
"The two passwords do not match"
,
"de_DE"
:
"Die zwei Passwörter stimmt nicht überein"
},
"phone_registered"
:
{
"zh_CN"
:
"该手机号已注册"
,
"en_US"
:
"This phone number has already been registered"
,
"de_DE"
:
"Diese Telefonnummer ist bereits registriert"
},
"user_save_suc"
:
{
"zh_CN"
:
"保存用户信息成功"
,
"en_US"
:
"User information saved successfully"
,
"de_DE"
:
"Benutzerdaten erfolgreich gespeichert"
},
"unbind_wechat_suc"
:
{
"zh_CN"
:
"解除微信绑定成功"
,
"en_US"
:
"Unbinding WeChat has been successful"
,
"de_DE"
:
"WeChat- binding erfolgreich gelöst "
},
"phone_no_reg_dea"
:
{
"zh_CN"
:
"手机号未注册或已注销"
,
"en_US"
:
"The phone number is not registered or has been deactivated"
,
"de_DE"
:
"Telefonnummer nicht registriert oder abgemeldet"
},
"phone_not_reg"
:
{
"zh_CN"
:
"手机号未注册"
,
"en_US"
:
"The phone number is not registered"
,
"de_DE"
:
"Telefonnummer nicht registriert"
},
"succeed"
:
{
"zh_CN"
:
"成功"
,
"en_US"
:
"succeed"
,
"de_DE"
:
"Erfolg"
},
"direct_info_page"
:
{
"zh_CN"
:
"跳转填写页面"
,
"en_US"
:
"Skip fill page"
,
"de_DE"
:
"Springen Sie zur Seite zum Ausfüllen von Informationen"
},
},
}
}
unify_api/modules/common/procedures/multi_lang.py
View file @
9d7ffbce
...
@@ -5,7 +5,8 @@ DATE:2024/5/30 11:34
...
@@ -5,7 +5,8 @@ DATE:2024/5/30 11:34
"""
"""
from
pot_libs.logger
import
log
from
pot_libs.logger
import
log
from
unify_api.constants
import
(
from
unify_api.constants
import
(
E_TYPE_MSG_LANG
,
PHASE_LINE_LANG
,
E_TYPE_NAME_LANG
,
LOG_IN_TIPS
E_TYPE_MSG_LANG
,
PHASE_LINE_LANG
,
E_TYPE_NAME_LANG
,
LOG_IN_TIPS
,
PRODUCT_INFOS
,
PRODUCT_NAME
)
)
...
@@ -45,3 +46,14 @@ def load_e_type_name(e_type, lang="zh_CN"):
...
@@ -45,3 +46,14 @@ def load_e_type_name(e_type, lang="zh_CN"):
def
load_login_tips
(
err_type
,
lang
=
"zh_CN"
):
def
load_login_tips
(
err_type
,
lang
=
"zh_CN"
):
return
LOG_IN_TIPS
.
get
(
err_type
,
{})
.
get
(
lang
,
""
)
return
LOG_IN_TIPS
.
get
(
err_type
,
{})
.
get
(
lang
,
""
)
def
load_product_info
(
prod_id
,
lang
=
"zh_CN"
):
if
prod_id
not
in
PRODUCT_INFOS
:
return
{}
prod_info
=
PRODUCT_INFOS
[
prod_id
]
prod_name
=
PRODUCT_NAME
.
get
(
prod_id
,
{})
.
get
(
lang
)
if
prod_name
:
prod_info
[
"name"
]
=
prod_name
return
prod_info
unify_api/modules/users/procedures/login_pds.py
View file @
9d7ffbce
...
@@ -26,7 +26,8 @@ async def wechat_login(args, host):
...
@@ -26,7 +26,8 @@ async def wechat_login(args, host):
}
}
try
:
try
:
log
.
info
(
f
"request auth_url={SETTING.auth_url} request_body = {request_body}"
)
log
.
info
(
f
"request auth_url={SETTING.auth_url} request_body = {request_body}"
)
resp_str
,
status
=
await
AioHttpUtils
()
.
post
(
resp_str
,
status
=
await
AioHttpUtils
()
.
post
(
SETTING
.
auth_url
,
SETTING
.
auth_url
,
request_body
,
request_body
,
...
@@ -54,7 +55,8 @@ async def app_login(args, host):
...
@@ -54,7 +55,8 @@ async def app_login(args, host):
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
"unionid is None"
}
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
"unionid is None"
}
try
:
try
:
log
.
info
(
f
"request auth_url={SETTING.auth_url} request_body = {request_body}"
)
log
.
info
(
f
"request auth_url={SETTING.auth_url} request_body = {request_body}"
)
resp_str
,
status
=
await
AioHttpUtils
()
.
post
(
resp_str
,
status
=
await
AioHttpUtils
()
.
post
(
SETTING
.
auth_url
,
SETTING
.
auth_url
,
request_body
,
request_body
,
...
@@ -86,7 +88,8 @@ async def web_login(args, host):
...
@@ -86,7 +88,8 @@ async def web_login(args, host):
request_body
,
request_body
,
timeout
=
50
,
timeout
=
50
,
)
)
log
.
info
(
f
"web_login request auth_url resp_str={resp_str} status={status}"
)
log
.
info
(
f
"web_login request auth_url resp_str={resp_str} status={status}"
)
resp
=
json
.
loads
(
resp_str
)
resp
=
json
.
loads
(
resp_str
)
if
status
==
301
:
if
status
==
301
:
return
301
,
{
"code"
:
30001
,
"data"
:
{
"wechat_id"
:
return
301
,
{
"code"
:
30001
,
"data"
:
{
"wechat_id"
:
...
@@ -131,7 +134,9 @@ async def third_login(args, host, lang):
...
@@ -131,7 +134,9 @@ async def third_login(args, host, lang):
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
resp
=
json
.
loads
(
resp_str
)
resp
=
json
.
loads
(
resp_str
)
if
status
==
200
:
if
status
==
200
:
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
"成功"
}
# 成功
tip
=
load_login_tips
(
"succeed"
,
lang
)
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
tip
}
else
:
else
:
return
401
,
{
return
401
,
{
"code"
:
40001
,
"code"
:
40001
,
...
@@ -172,7 +177,9 @@ async def web_third_login(args, host, lang):
...
@@ -172,7 +177,9 @@ async def web_third_login(args, host, lang):
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
resp
=
json
.
loads
(
resp_str
)
resp
=
json
.
loads
(
resp_str
)
if
status
==
200
:
if
status
==
200
:
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
"成功"
}
# 成功
tip
=
load_login_tips
(
"succeed"
,
lang
)
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
tip
}
else
:
else
:
log
.
info
(
f
"request resp={resp}"
)
log
.
info
(
f
"request resp={resp}"
)
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
...
@@ -191,7 +198,10 @@ async def validation_login(args, host, lang):
...
@@ -191,7 +198,10 @@ async def validation_login(args, host, lang):
# 1. 对参数校验
# 1. 对参数校验
if
not
re
.
match
(
r'^1[3-9]\d{9}$'
,
phone
):
if
not
re
.
match
(
r'^1[3-9]\d{9}$'
,
phone
):
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
"手机号码格式错误"
}
# 手机号码格式错误
tip
=
load_login_tips
(
"err_phone_fmt"
,
lang
)
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
tip
}
if
not
all
([
phone
,
verify_client
]):
if
not
all
([
phone
,
verify_client
]):
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_uname_pwd_tip
}
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_uname_pwd_tip
}
# 效验验证码
# 效验验证码
...
@@ -200,13 +210,13 @@ async def validation_login(args, host, lang):
...
@@ -200,13 +210,13 @@ async def validation_login(args, host, lang):
err_vfy_code_tip
=
load_login_tips
(
"err_vfy_code"
,
lang
)
err_vfy_code_tip
=
load_login_tips
(
"err_vfy_code"
,
lang
)
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_vfy_code_tip
}
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_vfy_code_tip
}
# verify_server = await RedisClient().get(f"sms:sms_{phone}")
# if verify_server != verify_client:
# return 401, {"code": 40001, "data": None, "message": "验证码错误"}
user
=
await
user_by_phone_number
(
phone
)
user
=
await
user_by_phone_number
(
phone
)
if
not
user
:
if
not
user
:
# 不存在用户,通知前端跳转填写信息页面
# 不存在用户,通知前端跳转填写信息页面
return
301
,
{
"code"
:
30001
,
"data"
:
None
,
"message"
:
"跳转填写页面"
}
# 跳转填写页面
tip
=
load_login_tips
(
"direct_info_page"
,
lang
)
return
301
,
{
"code"
:
30001
,
"data"
:
None
,
"message"
:
tip
}
# 1. 准备转发给auth服务的参数
# 1. 准备转发给auth服务的参数
request_body
=
{
request_body
=
{
"phone"
:
phone
,
"phone"
:
phone
,
...
@@ -224,7 +234,9 @@ async def validation_login(args, host, lang):
...
@@ -224,7 +234,9 @@ async def validation_login(args, host, lang):
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
log
.
info
(
f
"request auth_url resp_str={resp_str} status={status}"
)
resp
=
json
.
loads
(
resp_str
)
resp
=
json
.
loads
(
resp_str
)
if
status
==
200
:
if
status
==
200
:
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
"成功"
}
# 成功
tip
=
load_login_tips
(
"succeed"
,
lang
)
return
200
,
{
"code"
:
200
,
"data"
:
resp
,
"message"
:
tip
}
else
:
else
:
return
401
,
{
return
401
,
{
"code"
:
40001
,
"code"
:
40001
,
...
@@ -246,6 +258,7 @@ class ExtAuthentication(Authentication):
...
@@ -246,6 +258,7 @@ class ExtAuthentication(Authentication):
if
args
.
get
(
"user_name"
)
==
"balabala"
and
args
.
get
(
if
args
.
get
(
"user_name"
)
==
"balabala"
and
args
.
get
(
"password"
)
==
"balabala"
and
int
(
SETTING
.
debug_mode
)
==
1
:
"password"
)
==
"balabala"
and
int
(
SETTING
.
debug_mode
)
==
1
:
return
{
"user_id"
:
88
}
return
{
"user_id"
:
88
}
client_name
=
args
.
get
(
"client_name"
)
client_name
=
args
.
get
(
"client_name"
)
host
=
request
.
host
host
=
request
.
host
user_id
,
message
=
0
,
"未经认证"
user_id
,
message
=
0
,
"未经认证"
...
...
unify_api/modules/users/views/current_user_info.py
View file @
9d7ffbce
...
@@ -11,13 +11,15 @@ from unify_api.modules.users.components.current_user_info_cps import *
...
@@ -11,13 +11,15 @@ from unify_api.modules.users.components.current_user_info_cps import *
from
pot_libs.common.components.responses
import
success_res
from
pot_libs.common.components.responses
import
success_res
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
unify_api.modules.users.procedures.send_sms
import
sample
from
unify_api.modules.users.procedures.send_sms
import
sample
from
pot_libs.aredis_util
import
aredis_u
tils
from
pot_libs.aredis_util
.aredis_utils
import
RedisU
tils
from
unify_api.modules.users.dao.current_user_info_dao
import
*
from
unify_api.modules.users.dao.current_user_info_dao
import
*
from
unify_api.modules.common.dao.common_dao
import
user_by_phone_number
,
\
from
unify_api.modules.common.dao.common_dao
import
user_by_phone_number
,
\
user_by_user_id
user_by_user_id
from
pot_libs.aiohttp_util.aiohttp_utils
import
AioHttpUtils
from
pot_libs.aiohttp_util.aiohttp_utils
import
AioHttpUtils
from
unify_api.modules.common.dao.common_dao
import
load_user_lang
from
unify_api.modules.common.dao.common_dao
import
load_user_lang
from
unify_api.modules.common.procedures.multi_lang
import
load_login_tips
from
unify_api.modules.common.procedures.multi_lang
import
(
load_login_tips
,
load_product_info
)
from
unify_api.modules.users.procedures.jwt_user
import
auth_phone_verify
,
\
from
unify_api.modules.users.procedures.jwt_user
import
auth_phone_verify
,
\
check_password
check_password
...
@@ -56,13 +58,17 @@ async def get_user_info(request) -> UserInfoResponse:
...
@@ -56,13 +58,17 @@ async def get_user_info(request) -> UserInfoResponse:
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
pro_info
=
await
conn
.
fetchall
(
sql
=
pro_sql
,
args
=
(
int
(
user_id
)),
)
pro_info
=
await
conn
.
fetchall
(
sql
=
pro_sql
,
args
=
(
int
(
user_id
)),
)
# [{'product': 1}, {'product': 2}, {'product': 3}]
# [{'product': 1}, {'product': 2}, {'product': 3}]
lang
=
user_info
[
"lang"
]
product_list
=
[]
product_list
=
[]
if
pro_info
:
if
pro_info
:
for
pro
in
pro_info
:
for
pro
in
pro_info
:
# ulock的app产品跳过, PRODUCT_INFOS只存u+云的产品
# ulock的app产品跳过, PRODUCT_INFOS只存u+云的产品
if
pro
[
"product"
]
not
in
PRODUCT_INFOS
:
if
pro
[
"product"
]
not
in
PRODUCT_INFOS
:
continue
continue
product_list
.
append
(
PRODUCT_INFOS
[
pro
[
"product"
]])
d_prod_info
=
load_product_info
(
pro
[
"product"
],
lang
)
product_list
.
append
(
d_prod_info
)
product_list
=
sorted
(
product_list
,
key
=
lambda
x
:
x
[
"sort_num"
])
product_list
=
sorted
(
product_list
,
key
=
lambda
x
:
x
[
"sort_num"
])
# 4. 查询zhiweiu权限, 默认普通用户
# 4. 查询zhiweiu权限, 默认普通用户
zhiweiu_auth
=
user_info
.
get
(
"zhiweiu_auth"
)
zhiweiu_auth
=
user_info
.
get
(
"zhiweiu_auth"
)
...
@@ -78,39 +84,51 @@ async def get_user_info(request) -> UserInfoResponse:
...
@@ -78,39 +84,51 @@ async def get_user_info(request) -> UserInfoResponse:
unit
=
user_info
.
get
(
"unit"
),
unit
=
user_info
.
get
(
"unit"
),
product_list
=
product_list
,
product_list
=
product_list
,
zhiweiu_auth
=
zhiweiu_auth
,
zhiweiu_auth
=
zhiweiu_auth
,
lang
=
user_info
[
"lang"
]
lang
=
lang
)
)
@
summary
(
"发送手机验证码"
)
@
summary
(
"发送手机验证码"
)
async
def
get_send_sms
(
request
):
async
def
get_send_sms
(
request
):
phone
=
request
.
args
.
get
(
"phone"
)
phone
=
request
.
args
.
get
(
"phone"
)
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
if
re
.
match
(
r'^1[3-9]\d{9}$'
,
phone
):
if
re
.
match
(
r'^1[3-9]\d{9}$'
,
phone
):
send_flag
=
await
aredis_utils
.
RedisUtils
()
.
get
(
send_flag
=
await
RedisUtils
()
.
get
(
f
"sms:send_sms_flag_{phone}"
)
f
"sms:send_sms_flag_{phone}"
)
if
send_flag
:
if
send_flag
:
return
success_res
(
code
=
RET
.
send_sms_quick
,
msg
=
"请求验证码过于频繁"
)
# 请求验证码过于频繁
vfy_code_freq_tip
=
load_login_tips
(
"vfy_code_freq"
,
lang
)
return
success_res
(
code
=
RET
.
send_sms_quick
,
msg
=
vfy_code_freq_tip
)
code
=
'
%06
d'
%
random
.
randint
(
1
,
999999
)
code
=
'
%06
d'
%
random
.
randint
(
1
,
999999
)
# 短信间隔
# 短信间隔
await
aredis_utils
.
RedisUtils
()
.
setex
(
await
RedisUtils
()
.
setex
(
f
"sms:send_sms_flag_{phone}"
,
VALIDATION_EXP
,
f
"sms:send_sms_flag_{phone}"
,
VALIDATION_EXP
,
1
)
1
)
await
aredis_utils
.
RedisUtils
()
.
setex
(
await
RedisUtils
()
.
setex
(
f
"sms:sms_{phone}"
,
AUTH_EXP
,
code
)
f
"sms:sms_{phone}"
,
AUTH_EXP
,
code
)
result_body
=
sample
.
main
([
phone
,
code
])
result_body
=
sample
.
main
([
phone
,
code
])
log
.
info
(
f
"send_sms {phone}, {code}, {result_body}"
)
log
.
info
(
f
"send_sms {phone}, {code}, {result_body}"
)
if
result_body
.
code
==
"OK"
:
if
result_body
.
code
==
"OK"
:
return
success_res
(
msg
=
"发送成功"
)
# 发送成功
tip
=
load_login_tips
(
"send_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
else
:
else
:
if
result_body
.
message
==
"触发天级流控Permits:10"
:
if
result_body
.
message
==
"触发天级流控Permits:10"
:
msg
=
"您今日发送短信次数已用完"
# 您今日发送短信次数已用完
tip
=
load_login_tips
(
"msg_send_lim"
,
lang
)
elif
result_body
.
message
==
"触发小时级流控Permits:5"
:
elif
result_body
.
message
==
"触发小时级流控Permits:5"
:
msg
=
"请求验证码过于频繁,请1小时后重新发送"
# 请求验证码过于频繁,请1小时后重新发送
tip
=
load_login_tips
(
"vfy_code_freq_hr"
,
lang
)
elif
result_body
.
message
==
"触发分钟级流控Permits:1"
:
elif
result_body
.
message
==
"触发分钟级流控Permits:1"
:
msg
=
"请求验证码过于频繁,请1分钟后重新发送"
# 请求验证码过于频繁,请1分钟后重新发送
tip
=
load_login_tips
(
"vfy_code_freq_min"
,
lang
)
else
:
else
:
msg
=
"验证码发送失败"
# 验证码发送失败
return
success_res
(
code
=
RET
.
send_sms_quick2
,
msg
=
msg
)
tip
=
load_login_tips
(
"vfy_code_send_fail"
,
lang
)
return
success_res
(
code
=
RET
.
send_sms_fail
,
msg
=
"手机号码不合法"
)
return
success_res
(
code
=
RET
.
send_sms_quick2
,
msg
=
tip
)
# 手机号码不合法
tip
=
load_login_tips
(
"phone_not_invalid"
,
lang
)
return
success_res
(
code
=
RET
.
send_sms_fail
,
msg
=
tip
)
@
summary
(
"首次登录保存用户信息"
)
@
summary
(
"首次登录保存用户信息"
)
...
@@ -123,15 +141,21 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -123,15 +141,21 @@ async def post_save_userinfo(request, body: SaveUserReq):
password2
=
body
.
password2
password2
=
body
.
password2
wechat_id
=
body
.
wechat_id
wechat_id
=
body
.
wechat_id
verify
=
body
.
verify
verify
=
body
.
verify
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
if
not
all
([
real_name
,
job
,
unit
,
phone
,
password
]):
if
not
all
([
real_name
,
job
,
unit
,
phone
,
password
]):
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
"缺少必传参数"
)
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
"缺少必传参数"
)
if
password
!=
password2
:
if
password
!=
password2
:
return
success_res
(
code
=
RET
.
password_error
,
msg
=
"两次密码不一致"
)
# 两次密码不一致
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
password_error
,
msg
=
tip
)
passwd
=
check_password
(
password
)
passwd
=
check_password
(
password
)
if
verify
:
if
verify
:
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
if
not
auth_verify
:
if
not
auth_verify
:
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"验证码不一致"
)
# 验证码不一致
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
if
wechat_id
:
if
wechat_id
:
wechat_info
=
await
is_having_wechat_id
(
wechat_id
)
wechat_info
=
await
is_having_wechat_id
(
wechat_id
)
is_having
=
await
phone_is_having_dao
(
phone
)
is_having
=
await
phone_is_having_dao
(
phone
)
...
@@ -139,7 +163,9 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -139,7 +163,9 @@ async def post_save_userinfo(request, body: SaveUserReq):
await
update_user_info_by_wechat_id
(
real_name
,
unit
,
job
,
passwd
,
await
update_user_info_by_wechat_id
(
real_name
,
unit
,
job
,
passwd
,
phone
,
wechat_id
)
phone
,
wechat_id
)
elif
is_having
and
is_having
[
"wechat_id"
]:
elif
is_having
and
is_having
[
"wechat_id"
]:
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"该手机号已注册"
)
# 该手机号已注册
tip
=
load_login_tips
(
"phone_registered"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
elif
is_having
:
elif
is_having
:
# 修改信息
# 修改信息
await
update_user_info
(
real_name
,
unit
,
job
,
passwd
,
phone
,
await
update_user_info
(
real_name
,
unit
,
job
,
passwd
,
phone
,
...
@@ -169,7 +195,9 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -169,7 +195,9 @@ async def post_save_userinfo(request, body: SaveUserReq):
if
status
==
200
:
if
status
==
200
:
return
success_res
(
data
=
resp
)
return
success_res
(
data
=
resp
)
else
:
else
:
return
success_res
(
msg
=
"保存用户信息成功"
)
# 保存用户信息成功
tip
=
load_login_tips
(
"user_save_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"修改手机号"
)
@
summary
(
"修改手机号"
)
...
@@ -205,7 +233,9 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -205,7 +233,9 @@ async def post_update_phone(request, body: UpdatePhoneReq):
# 效验验证码
# 效验验证码
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
if
not
auth_verify
:
if
not
auth_verify
:
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"验证码不一致"
)
# 验证码不一致
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
user_product_auth
=
await
load_user_product_auth
(
user_id
)
user_product_auth
=
await
load_user_product_auth
(
user_id
)
user_product_auth_dict
=
\
user_product_auth_dict
=
\
...
@@ -253,7 +283,11 @@ async def post_auth_phone(request, body: AuthPhoneReq):
...
@@ -253,7 +283,11 @@ async def post_auth_phone(request, body: AuthPhoneReq):
verify
=
body
.
verify
verify
=
body
.
verify
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
if
not
auth_verify
:
if
not
auth_verify
:
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"验证码不一致"
)
# 验证码不一致
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
return
success_res
(
msg
=
"验证通过"
)
return
success_res
(
msg
=
"验证通过"
)
...
@@ -262,20 +296,30 @@ async def post_back_password(request, body: PhoneIsHavingReq):
...
@@ -262,20 +296,30 @@ async def post_back_password(request, body: PhoneIsHavingReq):
phone
=
body
.
phone
phone
=
body
.
phone
is_delete
=
await
phone_is_having_dao
(
phone
)
is_delete
=
await
phone_is_having_dao
(
phone
)
if
not
is_delete
:
if
not
is_delete
:
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
"手机号未注册或已注销"
)
# 手机号未注册或已注销
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
tip
=
load_login_tips
(
"phone_no_reg_dea"
,
lang
)
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
tip
)
return
success_res
(
msg
=
"成功"
)
return
success_res
(
msg
=
"成功"
)
@
summary
(
"修改密码"
)
@
summary
(
"修改密码"
)
async
def
post_update_password
(
request
,
body
:
UpdatePasswordReq
):
async
def
post_update_password
(
request
,
body
:
UpdatePasswordReq
):
phone
=
body
.
phone
phone
=
body
.
phone
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
is_delete
=
await
phone_is_having_dao
(
phone
)
is_delete
=
await
phone_is_having_dao
(
phone
)
if
not
is_delete
:
if
not
is_delete
:
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
"手机号未注册"
)
# 手机号未注册
tip
=
load_login_tips
(
"phone_not_reg"
,
lang
)
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
tip
)
password
=
body
.
password
password
=
body
.
password
password2
=
body
.
password2
password2
=
body
.
password2
if
password
!=
password2
:
if
password
!=
password2
:
return
success_res
(
code
=
RET
.
password_error
,
msg
=
"两次密码不一致"
)
# 两次密码不一致
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
password_error
,
msg
=
tip
)
passwd
=
check_password
(
password
)
passwd
=
check_password
(
password
)
await
update_password_dao
(
phone
,
passwd
)
await
update_password_dao
(
phone
,
passwd
)
return
success_res
(
msg
=
"修改成功"
)
return
success_res
(
msg
=
"修改成功"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment