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
e1ab4310
Commit
e1ab4310
authored
Jun 19, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix log mutil lang 2024-06-19
parent
50a5b41e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
163 additions
and
40 deletions
+163
-40
constants.py
unify_api/constants.py
+58
-2
login_pds.py
unify_api/modules/users/procedures/login_pds.py
+16
-11
auth.py
unify_api/modules/users/views/auth.py
+1
-1
current_user_info.py
unify_api/modules/users/views/current_user_info.py
+88
-26
No files found.
unify_api/constants.py
View file @
e1ab4310
...
@@ -419,7 +419,7 @@ PRODUCT_INFOS = {
...
@@ -419,7 +419,7 @@ PRODUCT_INFOS = {
},
},
7
:
{
7
:
{
"name"
:
"识电U新版"
,
"name"
:
"识电U新版"
,
"url"
:
SETTING
.
shidianu_new
_url
,
"url"
:
SETTING
.
comp_energy
_url
,
"img_url"
:
f
"{SETTING.download_img_url}/image/new-shidianu.png"
,
"img_url"
:
f
"{SETTING.download_img_url}/image/new-shidianu.png"
,
"sort_num"
:
31
"sort_num"
:
31
},
},
...
@@ -884,7 +884,27 @@ LOG_IN_TIPS = {
...
@@ -884,7 +884,27 @@ LOG_IN_TIPS = {
"unbind_wechat_suc"
:
{
"unbind_wechat_suc"
:
{
"zh_CN"
:
"解除微信绑定成功"
,
"zh_CN"
:
"解除微信绑定成功"
,
"en_US"
:
"Unbinding WeChat has been successful"
,
"en_US"
:
"Unbinding WeChat has been successful"
,
"de_DE"
:
"WeChat- binding erfolgreich gelöst "
"de_DE"
:
"WeChat- binding erfolgreich gelöst"
},
"wechat_bind_suc"
:
{
"zh_CN"
:
"微信绑定成功"
,
"en_US"
:
"WeChat binding successful"
,
"de_DE"
:
"WeChat-Bindung erfolgreich"
},
"wechat_bind_fail"
:
{
"zh_CN"
:
"微信绑定失败"
,
"en_US"
:
"WeChat binding failed"
,
"de_DE"
:
"Die WeChat-Bindung ist fehlgeschlagen"
},
"wechat_bound"
:
{
"zh_CN"
:
"该微信号已经被绑定"
,
"en_US"
:
"This WeChat ID has been bound"
,
"de_DE"
:
"Diese WeChat-ID wurde gebunden"
},
"phone_no_usable"
:
{
"zh_CN"
:
"该手机号码可用"
,
"en_US"
:
"The phone number is available"
,
"de_DE"
:
"Die Handynummer ist verfügbar"
},
},
"phone_no_reg_dea"
:
{
"phone_no_reg_dea"
:
{
"zh_CN"
:
"手机号未注册或已注销"
,
"zh_CN"
:
"手机号未注册或已注销"
,
...
@@ -901,9 +921,45 @@ LOG_IN_TIPS = {
...
@@ -901,9 +921,45 @@ LOG_IN_TIPS = {
"en_US"
:
"succeed"
,
"en_US"
:
"succeed"
,
"de_DE"
:
"Erfolg"
"de_DE"
:
"Erfolg"
},
},
"fail"
:
{
"zh_CN"
:
"失败"
,
"en_US"
:
"fail"
,
"de_DE"
:
"scheitern"
},
"direct_info_page"
:
{
"direct_info_page"
:
{
"zh_CN"
:
"跳转填写页面"
,
"zh_CN"
:
"跳转填写页面"
,
"en_US"
:
"Skip fill page"
,
"en_US"
:
"Skip fill page"
,
"de_DE"
:
"Springen Sie zur Seite zum Ausfüllen von Informationen"
"de_DE"
:
"Springen Sie zur Seite zum Ausfüllen von Informationen"
},
},
"miss_req_param"
:
{
"zh_CN"
:
"缺少必传参数"
,
"en_US"
:
"Missing required parameters"
,
"de_DE"
:
"Erforderliche Parameter fehlen"
},
"update_suc"
:
{
"zh_CN"
:
"修改成功"
,
"en_US"
:
"Successfully modified"
,
"de_DE"
:
"Erfolgreich geändert"
},
"vfy_pass"
:
{
"zh_CN"
:
"验证通过"
,
"en_US"
:
"Verification passed"
,
"de_DE"
:
"Verifizierung bestanden"
},
"miss_param"
:
{
"zh_CN"
:
"缺少参数"
,
"en_US"
:
"Missing parameters"
,
"de_DE"
:
"Fehlende Parameter"
},
"logout_suc"
:
{
"zh_CN"
:
"注销成功"
,
"en_US"
:
"Logout successful"
,
"de_DE"
:
"Abmeldung erfolgreich"
},
"account_no_auth"
:
{
"zh_CN"
:
"当前账号无权限,请联系管理人员"
,
"en_US"
:
"The current account does not have permission, please contact the administrator"
,
"de_DE"
:
"Für das aktuelle Konto ist keine Berechtigung vorhanden. Bitte wenden Sie sich an den Administrator"
},
}
}
unify_api/modules/users/procedures/login_pds.py
View file @
e1ab4310
...
@@ -70,7 +70,7 @@ async def app_login(args, host):
...
@@ -70,7 +70,7 @@ async def app_login(args, host):
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
str
(
e
)}
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
str
(
e
)}
async
def
web_login
(
args
,
host
):
async
def
web_login
(
args
,
host
,
lang
):
"""web登录"""
"""web登录"""
# 1. 准备转发给auth服务的参数
# 1. 准备转发给auth服务的参数
request_body
=
{
request_body
=
{
...
@@ -88,17 +88,23 @@ async def web_login(args, host):
...
@@ -88,17 +88,23 @@ async def web_login(args, host):
request_body
,
request_body
,
timeout
=
50
,
timeout
=
50
,
)
)
log
.
info
(
log
.
info
(
f
"web_login request auth_url rsp={resp_str} status={status}"
)
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"
:
# 跳转填写页面
resp
[
'reasons'
][
0
]},
tip
=
load_login_tips
(
"direct_info_page"
,
lang
)
"message"
:
"跳转填写页面"
}
return
301
,
{
"code"
:
30001
,
"data"
:
{
"wechat_id"
:
resp
[
'reasons'
][
0
]},
"message"
:
tip
}
elif
status
==
200
:
elif
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
,
{
"code"
:
40001
,
"data"
:
resp
,
"message"
:
"失败"
}
# 失败
tip
=
load_login_tips
(
"fail"
,
lang
)
return
401
,
{
"code"
:
40001
,
"data"
:
resp
,
"message"
:
tip
}
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
return
401
,
{
"code"
:
401
,
"data"
:
None
,
"message"
:
str
(
e
)}
return
401
,
{
"code"
:
401
,
"data"
:
None
,
"message"
:
str
(
e
)}
...
@@ -212,9 +218,8 @@ async def validation_login(args, host, lang):
...
@@ -212,9 +218,8 @@ async def validation_login(args, host, lang):
user
=
await
user_by_phone_number
(
phone
)
user
=
await
user_by_phone_number
(
phone
)
if
not
user
:
if
not
user
:
# 不存在用户,通知前端跳转填写信息页面
# 当前账号无权限,请联系管理人员
# 跳转填写页面
tip
=
load_login_tips
(
"account_no_auth"
,
lang
)
tip
=
load_login_tips
(
"direct_info_page"
,
lang
)
return
301
,
{
"code"
:
30001
,
"data"
:
None
,
"message"
:
tip
}
return
301
,
{
"code"
:
30001
,
"data"
:
None
,
"message"
:
tip
}
# 1. 准备转发给auth服务的参数
# 1. 准备转发给auth服务的参数
...
...
unify_api/modules/users/views/auth.py
View file @
e1ab4310
...
@@ -49,7 +49,7 @@ class AuthView(HTTPMethodView):
...
@@ -49,7 +49,7 @@ class AuthView(HTTPMethodView):
# 自定义状态码
# 自定义状态码
resp_body
[
"code"
]
=
40001
resp_body
[
"code"
]
=
40001
elif
client_name
==
"web"
:
elif
client_name
==
"web"
:
status_code
,
resp_body
=
await
web_login
(
args
,
host
)
status_code
,
resp_body
=
await
web_login
(
args
,
host
,
lang
)
if
status_code
==
401
:
if
status_code
==
401
:
resp_body
[
"code"
]
=
40001
resp_body
[
"code"
]
=
40001
elif
client_name
==
"script"
:
elif
client_name
==
"script"
:
...
...
unify_api/modules/users/views/current_user_info.py
View file @
e1ab4310
...
@@ -64,10 +64,15 @@ async def get_user_info(request) -> UserInfoResponse:
...
@@ -64,10 +64,15 @@ async def get_user_info(request) -> UserInfoResponse:
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
:
prod_id
=
pro
[
"product"
]
if
prod_id
not
in
PRODUCT_INFOS
or
prod_id
in
(
1
,):
continue
continue
d_prod_info
=
load_product_info
(
pro
[
"product"
],
lang
)
d_prod_info
=
load_product_info
(
prod_id
,
lang
)
product_list
.
append
(
d_prod_info
)
if
product_list
:
d_prod_info
=
load_product_info
(
7
,
lang
)
product_list
.
append
(
d_prod_info
)
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权限, 默认普通用户
...
@@ -144,11 +149,15 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -144,11 +149,15 @@ async def post_save_userinfo(request, body: SaveUserReq):
user_id
=
jwt_user
(
request
)
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
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
=
"缺少必传参数"
)
# 缺少必传参数
tip
=
load_login_tips
(
"miss_req_param"
,
lang
)
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
tip
)
if
password
!=
password2
:
if
password
!=
password2
:
# 两次密码不一致
# 两次密码不一致
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
password_error
,
msg
=
tip
)
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
)
...
@@ -156,6 +165,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -156,6 +165,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
# 验证码不一致
# 验证码不一致
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
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
)
...
@@ -166,6 +176,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -166,6 +176,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
# 该手机号已注册
# 该手机号已注册
tip
=
load_login_tips
(
"phone_registered"
,
lang
)
tip
=
load_login_tips
(
"phone_registered"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
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
,
...
@@ -176,6 +187,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
...
@@ -176,6 +187,7 @@ async def post_save_userinfo(request, body: SaveUserReq):
wechat_id
)
wechat_id
)
else
:
else
:
await
insert_user_info
(
real_name
,
unit
,
job
,
passwd
,
phone
)
await
insert_user_info
(
real_name
,
unit
,
job
,
passwd
,
phone
)
user
=
await
user_by_phone_number
(
phone
)
user
=
await
user_by_phone_number
(
phone
)
# 获取token
# 获取token
request_body
=
{
request_body
=
{
...
@@ -215,13 +227,16 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -215,13 +227,16 @@ async def post_update_phone(request, body: UpdatePhoneReq):
if
phone_info
.
get
(
"wechat_id"
):
if
phone_info
.
get
(
"wechat_id"
):
err_tip
=
load_login_tips
(
"phone_bound"
,
lang
)
err_tip
=
load_login_tips
(
"phone_bound"
,
lang
)
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_tip
}
return
401
,
{
"code"
:
40001
,
"data"
:
None
,
"message"
:
err_tip
}
else
:
else
:
# 删除这条记录
# 删除这条记录
await
update_not_wechat
(
user_id
,
phone
)
await
update_not_wechat
(
user_id
,
phone
)
old_zhiwei_u
=
phone_info
[
"zhiweiu_auth"
]
old_zhiwei_u
=
phone_info
[
"zhiweiu_auth"
]
old_role
=
phone_info
[
"role"
]
old_role
=
phone_info
[
"role"
]
wechat_product_auth
=
await
\
wechat_product_auth
=
await
\
load_user_product_auth
(
phone_info
[
"user_id"
])
load_user_product_auth
(
phone_info
[
"user_id"
])
wechat_product_auth_dict
=
\
wechat_product_auth_dict
=
\
{
wechat_product
[
"product"
]:
wechat_product
[
"cid_ext"
]
{
wechat_product
[
"product"
]:
wechat_product
[
"cid_ext"
]
for
wechat_product
in
wechat_product_auth
}
\
for
wechat_product
in
wechat_product_auth
}
\
...
@@ -274,34 +289,43 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -274,34 +289,43 @@ async def post_update_phone(request, body: UpdatePhoneReq):
proxy
=
(
user_product_dict
.
get
(
key
)
or
wechat_product_dict
.
get
(
proxy
=
(
user_product_dict
.
get
(
key
)
or
wechat_product_dict
.
get
(
key
))
key
))
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
proxy
=
proxy
)
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
proxy
=
proxy
)
return
success_res
(
msg
=
"修改成功"
)
# 修改成功
tip
=
load_login_tips
(
"update_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"验证手机号"
)
@
summary
(
"验证手机号"
)
async
def
post_auth_phone
(
request
,
body
:
AuthPhoneReq
):
async
def
post_auth_phone
(
request
,
body
:
AuthPhoneReq
):
phone
=
body
.
phone
phone
=
body
.
phone
verify
=
body
.
verify
verify
=
body
.
verify
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
auth_verify
=
await
auth_phone_verify
(
phone
,
verify
)
if
not
auth_verify
:
if
not
auth_verify
:
# 验证码不一致
# 验证码不一致
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
tip
=
load_login_tips
(
"vfy_code_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
tip
)
return
success_res
(
msg
=
"验证通过"
)
# 验证通过
tip
=
load_login_tips
(
"vfy_pass"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"找回密码"
)
@
summary
(
"找回密码"
)
async
def
post_back_password
(
request
,
body
:
PhoneIsHavingReq
):
async
def
post_back_password
(
request
,
body
:
PhoneIsHavingReq
):
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
:
# 手机号未注册或已注销
# 手机号未注册或已注销
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
tip
=
load_login_tips
(
"phone_no_reg_dea"
,
lang
)
tip
=
load_login_tips
(
"phone_no_reg_dea"
,
lang
)
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
tip
)
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
tip
)
return
success_res
(
msg
=
"成功"
)
# 成功
tip
=
load_login_tips
(
"succeed"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"修改密码"
)
@
summary
(
"修改密码"
)
...
@@ -314,15 +338,20 @@ async def post_update_password(request, body: UpdatePasswordReq):
...
@@ -314,15 +338,20 @@ async def post_update_password(request, body: UpdatePasswordReq):
# 手机号未注册
# 手机号未注册
tip
=
load_login_tips
(
"phone_not_reg"
,
lang
)
tip
=
load_login_tips
(
"phone_not_reg"
,
lang
)
return
success_res
(
code
=
RET
.
phone_not_register
,
msg
=
tip
)
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
:
# 两次密码不一致
# 两次密码不一致
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
tip
=
load_login_tips
(
"passwd_inconst"
,
lang
)
return
success_res
(
code
=
RET
.
password_error
,
msg
=
tip
)
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
=
"修改成功"
)
# 修改成功
tip
=
load_login_tips
(
"update_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"获取个人信息"
)
@
summary
(
"获取个人信息"
)
...
@@ -345,7 +374,9 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
...
@@ -345,7 +374,9 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
job
=
body
.
job
job
=
body
.
job
lang
=
body
.
lang
lang
=
body
.
lang
if
not
any
([
name
,
unit
,
job
,
lang
]):
if
not
any
([
name
,
unit
,
job
,
lang
]):
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
"缺少参数"
)
# 缺少参数
tip
=
load_login_tips
(
"miss_param"
,
lang
)
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
tip
)
if
name
:
if
name
:
await
update_userinfo_dao
(
user_id
,
'real_name'
,
name
)
await
update_userinfo_dao
(
user_id
,
'real_name'
,
name
)
...
@@ -366,14 +397,22 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
...
@@ -366,14 +397,22 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
async
def
post_delete_wechat
(
request
,
body
:
UserinfoReq
)
\
async
def
post_delete_wechat
(
request
,
body
:
UserinfoReq
)
\
->
UserinfoResp
:
->
UserinfoResp
:
user_id
=
body
.
user_id
user_id
=
body
.
user_id
lang
=
await
load_user_lang
(
user_id
)
await
update_userinfo_dao
(
user_id
,
"wechat_id"
,
None
)
await
update_userinfo_dao
(
user_id
,
"wechat_id"
,
None
)
return
success_res
(
msg
=
"解除微信绑定成功"
)
# 解除微信绑定成功
tip
=
load_login_tips
(
"unbind_wechat_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"微信绑定"
)
@
summary
(
"微信绑定"
)
async
def
post_update_wechat
(
request
,
body
:
UpdateWechatReq
):
async
def
post_update_wechat
(
request
,
body
:
UpdateWechatReq
):
user_id
=
body
.
user_id
user_id
=
body
.
user_id
code
=
body
.
code
code
=
body
.
code
lang
=
await
load_user_lang
(
user_id
)
# 微信绑定失败
bind_fail_tip
=
load_login_tips
(
"wechat_bind_fail"
,
lang
)
# 1.通过code换取网页授权access_token
# 1.通过code换取网页授权access_token
url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=
%
s&"
\
url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=
%
s&"
\
"secret=
%
s&code=
%
s&grant_type=authorization_code"
%
\
"secret=
%
s&code=
%
s&grant_type=authorization_code"
%
\
...
@@ -383,20 +422,24 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -383,20 +422,24 @@ async def post_update_wechat(request, body: UpdateWechatReq):
log
.
info
(
f
"post_update_wechat res_token:{res_token}"
)
log
.
info
(
f
"post_update_wechat res_token:{res_token}"
)
if
token_status
!=
200
:
if
token_status
!=
200
:
log
.
error
(
"post_update_wechat get access_token fail"
)
log
.
error
(
"post_update_wechat get access_token fail"
)
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
"微信绑定失败"
)
# 微信绑定失败
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
bind_fail_tip
)
result
=
json
.
loads
(
res_token
)
result
=
json
.
loads
(
res_token
)
# 2.获取用户信息
# 2.获取用户信息
if
'access_token'
not
in
result
:
if
'access_token'
not
in
result
:
log
.
error
(
"post_update_wechat access_token not found"
)
log
.
error
(
"post_update_wechat access_token not found"
)
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
"微信绑定失败"
)
# 微信绑定失败
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
bind_fail_tip
)
url
=
"https://api.weixin.qq.com/sns/userinfo?access_token=
%
s&openid=
%
s"
\
url
=
"https://api.weixin.qq.com/sns/userinfo?access_token=
%
s&openid=
%
s"
\
%
(
result
[
'access_token'
],
result
[
'openid'
])
%
(
result
[
'access_token'
],
result
[
'openid'
])
res
,
user_info_status
=
await
AioHttpUtils
()
.
get
(
url
)
res
,
user_info_status
=
await
AioHttpUtils
()
.
get
(
url
)
log
.
info
(
f
"post_update_wechat user_info:{res}"
)
log
.
info
(
f
"post_update_wechat user_info:{res}"
)
if
user_info_status
!=
200
:
if
user_info_status
!=
200
:
log
.
error
(
"post_update_wechat get user info fail"
)
log
.
error
(
"post_update_wechat get user info fail"
)
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
"微信绑定失败"
)
# 微信绑定失败
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
bind_fail_tip
)
user_info
=
json
.
loads
(
res
)
user_info
=
json
.
loads
(
res
)
wechat_product_dict
,
old_zhiwei_u
,
old_role
=
{},
None
,
None
wechat_product_dict
,
old_zhiwei_u
,
old_role
=
{},
None
,
None
...
@@ -407,21 +450,25 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -407,21 +450,25 @@ async def post_update_wechat(request, body: UpdateWechatReq):
log
.
info
(
f
"post_update_wechat{data}, unionid:{unionid}"
)
log
.
info
(
f
"post_update_wechat{data}, unionid:{unionid}"
)
if
data
:
if
data
:
log
.
info
(
f
"post_update_wechat{data}"
)
log
.
info
(
f
"post_update_wechat{data}"
)
user_id
=
data
[
"user_id"
]
if
data
.
get
(
"phone_number"
):
if
data
.
get
(
"phone_number"
):
return
success_res
(
code
=
RET
.
wechat_repeat
,
# 该微信号已经被绑定
msg
=
"该微信号已经被绑定"
)
tip
=
load_login_tips
(
"wechat_bound"
,
lang
)
return
success_res
(
code
=
RET
.
wechat_repeat
,
msg
=
tip
)
else
:
else
:
old_zhiwei_u
=
data
[
"zhiweiu_auth"
]
old_zhiwei_u
=
data
[
"zhiweiu_auth"
]
old_role
=
data
[
"role"
]
old_role
=
data
[
"role"
]
r
=
'
%04
d'
%
random
.
randint
(
1
,
9999
)
r
=
'
%04
d'
%
random
.
randint
(
1
,
9999
)
new_wechat_id
=
f
"delete{r}{unionid}"
new_wechat_id
=
f
"delete{r}{unionid}"
# 删除老用户
# 删除老用户
await
update_user_is_delete
(
data
[
"user_id"
],
new_wechat_id
)
await
update_user_is_delete
(
user_id
,
new_wechat_id
)
# # 添加微信到新用户
# # 添加微信到新用户
# await update_not_phone(user_id, unionid)
# await update_not_phone(user_id, unionid)
# 修改权限
# 修改权限
wechat_product_auth
=
await
\
wechat_product_auth
=
await
load_user_product_auth
(
user_id
)
load_user_product_auth
(
data
[
"user_id"
])
wechat_product_auth_dict
=
\
wechat_product_auth_dict
=
\
{
wechat_product
[
"product"
]:
wechat_product
[
"cid_ext"
]
{
wechat_product
[
"product"
]:
wechat_product
[
"cid_ext"
]
for
wechat_product
in
wechat_product_auth
}
\
for
wechat_product
in
wechat_product_auth
}
\
...
@@ -430,6 +477,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -430,6 +477,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
{
wechat_product
[
"product"
]:
wechat_product
[
"proxy"
]
{
wechat_product
[
"product"
]:
wechat_product
[
"proxy"
]
for
wechat_product
in
wechat_product_auth
}
\
for
wechat_product
in
wechat_product_auth
}
\
if
wechat_product_auth
else
{}
if
wechat_product_auth
else
{}
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
=
\
{
user_product
[
"product"
]:
user_product
[
"cid_ext"
]
{
user_product
[
"product"
]:
user_product
[
"cid_ext"
]
...
@@ -467,25 +515,39 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -467,25 +515,39 @@ async def post_update_wechat(request, body: UpdateWechatReq):
else
:
else
:
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
proxy
)
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
proxy
)
log
.
info
(
f
"post_update_wechat product_auth:{product_auth}"
)
log
.
info
(
f
"post_update_wechat product_auth:{product_auth}"
)
return
success_res
(
msg
=
"微信绑定成功"
)
# 微信绑定成功
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
"微信绑定失败"
)
tip
=
load_login_tips
(
"wechat_bind_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
bind_fail_tip
)
@
summary
(
"手机号码是否被绑定"
)
@
summary
(
"手机号码是否被绑定"
)
async
def
post_phone_is_having
(
request
,
body
:
PhoneIsHavingReq
):
async
def
post_phone_is_having
(
request
,
body
:
PhoneIsHavingReq
):
phone
=
body
.
phone
phone
=
body
.
phone
user_id
=
jwt_user
(
request
)
lang
=
await
load_user_lang
(
user_id
)
data
=
await
phone_is_having_dao
(
phone
)
data
=
await
phone_is_having_dao
(
phone
)
if
data
:
if
data
:
return
success_res
(
code
=
RET
.
phone_repeat
,
msg
=
"该手机号码已经被绑定"
)
# 该手机号码已经被绑定
return
success_res
(
msg
=
"该手机号码可用"
)
tip
=
load_login_tips
(
"phone_bound"
,
lang
)
return
success_res
(
code
=
RET
.
phone_repeat
,
msg
=
tip
)
# 该手机号码可用
tip
=
load_login_tips
(
"phone_no_usable"
,
lang
)
return
success_res
(
msg
=
tip
)
@
summary
(
"注销用户"
)
@
summary
(
"注销用户"
)
async
def
post_delete_user
(
request
,
body
:
UserinfoReq
):
async
def
post_delete_user
(
request
,
body
:
UserinfoReq
):
user_id
=
body
.
user_id
user_id
=
body
.
user_id
lang
=
await
load_user_lang
(
user_id
)
data
=
await
user_by_user_id
(
user_id
)
data
=
await
user_by_user_id
(
user_id
)
code
=
'
%04
d'
%
random
.
randint
(
1
,
9999
)
code
=
'
%04
d'
%
random
.
randint
(
1
,
9999
)
new_wechat_id
=
f
"delete{code}"
+
data
[
"wechat_id"
]
\
new_wechat_id
=
f
"delete{code}"
+
data
[
"wechat_id"
]
\
if
data
[
"wechat_id"
]
else
None
if
data
[
"wechat_id"
]
else
None
await
update_user_is_delete
(
user_id
,
new_wechat_id
)
await
update_user_is_delete
(
user_id
,
new_wechat_id
)
return
success_res
(
msg
=
"注销成功"
)
# 注销成功
tip
=
load_login_tips
(
"logout_suc"
,
lang
)
return
success_res
(
msg
=
tip
)
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