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
cf293000
Commit
cf293000
authored
May 23, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lang switch 2024-05-32
parent
cd40d4c2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
19 deletions
+32
-19
current_user_info_cps.py
unify_api/modules/users/components/current_user_info_cps.py
+3
-0
current_user_info_dao.py
unify_api/modules/users/dao/current_user_info_dao.py
+1
-1
current_user_info.py
unify_api/modules/users/views/current_user_info.py
+28
-18
No files found.
unify_api/modules/users/components/current_user_info_cps.py
View file @
cf293000
...
@@ -13,6 +13,7 @@ class UserInfoResponse(Model, DbErr, UserErr, JwtErr):
...
@@ -13,6 +13,7 @@ class UserInfoResponse(Model, DbErr, UserErr, JwtErr):
unit
:
str
=
Str
(
'单位'
)
.
eg
(
"汇云中心"
)
unit
:
str
=
Str
(
'单位'
)
.
eg
(
"汇云中心"
)
product_list
:
list
=
List
(
"产品信息: 1-知电U+, 2-安电U+, 3-安电U+管理版"
)
.
eg
([
1
,
2
,
3
])
product_list
:
list
=
List
(
"产品信息: 1-知电U+, 2-安电U+, 3-安电U+管理版"
)
.
eg
([
1
,
2
,
3
])
zhiweiu_auth
:
int
=
Int
(
'用户权限:1-普通用户,2-运维用户'
)
.
eg
(
1
)
zhiweiu_auth
:
int
=
Int
(
'用户权限:1-普通用户,2-运维用户'
)
.
eg
(
1
)
lang
:
str
=
Str
(
"语言"
)
.
eg
(
"Chinese"
)
@
dataclass
()
@
dataclass
()
...
@@ -64,6 +65,7 @@ class UserinfoResp(Model):
...
@@ -64,6 +65,7 @@ class UserinfoResp(Model):
unit
:
str
=
Str
(
'公司'
)
.
eg
(
"10086"
)
unit
:
str
=
Str
(
'公司'
)
.
eg
(
"10086"
)
job
:
str
=
Str
(
'职业'
)
.
eg
(
"10086"
)
job
:
str
=
Str
(
'职业'
)
.
eg
(
"10086"
)
is_wechat
:
int
=
Int
(
'是否绑定微信 1 绑定 0未绑定'
)
.
eg
(
1
)
is_wechat
:
int
=
Int
(
'是否绑定微信 1 绑定 0未绑定'
)
.
eg
(
1
)
lang
:
str
=
Str
(
"语言"
)
.
eg
(
"Chinese"
)
@
dataclass
()
@
dataclass
()
...
@@ -72,6 +74,7 @@ class UpdateUserInfoReq(Model):
...
@@ -72,6 +74,7 @@ class UpdateUserInfoReq(Model):
name
:
str
=
Opt
(
Str
(
'姓名'
)
.
eg
(
"张三"
))
name
:
str
=
Opt
(
Str
(
'姓名'
)
.
eg
(
"张三"
))
unit
:
str
=
Opt
(
Str
(
'公司'
)
.
eg
(
"10086"
))
unit
:
str
=
Opt
(
Str
(
'公司'
)
.
eg
(
"10086"
))
job
:
str
=
Opt
(
Str
(
'职业'
)
.
eg
(
"10086"
))
job
:
str
=
Opt
(
Str
(
'职业'
)
.
eg
(
"10086"
))
lang
:
str
=
Opt
(
Str
(
"语言"
)
.
eg
(
"Chinese"
))
@
dataclass
()
@
dataclass
()
...
...
unify_api/modules/users/dao/current_user_info_dao.py
View file @
cf293000
...
@@ -82,7 +82,7 @@ async def update_user_is_delete(user_id, wechat_id):
...
@@ -82,7 +82,7 @@ async def update_user_is_delete(user_id, wechat_id):
await
conn
.
execute
(
sql
,
args
=
(
wechat_id
,
user_id
))
await
conn
.
execute
(
sql
,
args
=
(
wechat_id
,
user_id
))
async
def
search_user_product_auth_dao
(
user_id
):
async
def
load_user_product_auth
(
user_id
):
sql
=
"select product,cid_ext,proxy,uassistant_auth"
\
sql
=
"select product,cid_ext,proxy,uassistant_auth"
\
" from user_product_auth where user_id =
%
s "
" from user_product_auth where user_id =
%
s "
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
...
...
unify_api/modules/users/views/current_user_info.py
View file @
cf293000
...
@@ -75,7 +75,8 @@ async def get_user_info(request) -> UserInfoResponse:
...
@@ -75,7 +75,8 @@ async def get_user_info(request) -> UserInfoResponse:
real_name
=
user_info
.
get
(
"real_name"
),
real_name
=
user_info
.
get
(
"real_name"
),
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"
]
)
)
...
@@ -188,7 +189,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -188,7 +189,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
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
\
search_user_product_auth_dao
(
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
}
\
...
@@ -202,7 +203,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -202,7 +203,7 @@ async def post_update_phone(request, body: UpdatePhoneReq):
if
not
auth_verify
:
if
not
auth_verify
:
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"验证码不一致"
)
return
success_res
(
code
=
RET
.
verify_error
,
msg
=
"验证码不一致"
)
user_product_auth
=
await
search_user_product_auth_dao
(
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"
]
for
user_product
in
user_product_auth
}
if
user_product_auth
else
{}
for
user_product
in
user_product_auth
}
if
user_product_auth
else
{}
...
@@ -232,11 +233,13 @@ async def post_update_phone(request, body: UpdatePhoneReq):
...
@@ -232,11 +233,13 @@ async def post_update_phone(request, body: UpdatePhoneReq):
for
key
,
value
in
product_auth
.
items
():
for
key
,
value
in
product_auth
.
items
():
is_auth
=
await
search_product_auth_dao
(
user_id
,
key
)
is_auth
=
await
search_product_auth_dao
(
user_id
,
key
)
if
is_auth
:
if
is_auth
:
await
update_product_auth_dao
(
key
,
value
,
user_id
,
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
update_product_auth_dao
(
key
,
value
,
user_id
,
proxy
=
proxy
)
else
:
else
:
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
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
)
return
success_res
(
msg
=
"修改成功"
)
return
success_res
(
msg
=
"修改成功"
)
...
@@ -281,7 +284,8 @@ async def post_userinfo(request, body: UserinfoReq) -> UserinfoResp:
...
@@ -281,7 +284,8 @@ async def post_userinfo(request, body: UserinfoReq) -> UserinfoResp:
is_wechat
=
1
if
data
[
"wechat_id"
]
else
0
is_wechat
=
1
if
data
[
"wechat_id"
]
else
0
return
UserinfoResp
(
user_id
=
data
[
"user_id"
],
phone
=
data
[
"phone_number"
],
return
UserinfoResp
(
user_id
=
data
[
"user_id"
],
phone
=
data
[
"phone_number"
],
unit
=
data
.
get
(
"unit"
)
or
""
,
job
=
data
.
get
(
"job"
)
or
""
,
unit
=
data
.
get
(
"unit"
)
or
""
,
job
=
data
.
get
(
"job"
)
or
""
,
name
=
data
.
get
(
"real_name"
)
or
""
,
is_wechat
=
is_wechat
)
name
=
data
.
get
(
"real_name"
)
or
""
,
is_wechat
=
is_wechat
,
lang
=
data
[
"lang"
])
@
summary
(
"修改个人信息"
)
@
summary
(
"修改个人信息"
)
...
@@ -291,18 +295,22 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
...
@@ -291,18 +295,22 @@ async def post_update_userinfo(request, body: UpdateUserInfoReq) \
name
=
body
.
name
name
=
body
.
name
unit
=
body
.
unit
unit
=
body
.
unit
job
=
body
.
job
job
=
body
.
job
if
not
any
([
name
,
unit
,
job
]):
lang
=
body
.
lang
if
not
any
([
name
,
unit
,
job
,
lang
]):
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
"缺少参数"
)
return
success_res
(
code
=
RET
.
params_loss
,
msg
=
"缺少参数"
)
if
name
:
if
name
:
await
update_userinfo_dao
(
user_id
,
'real_name'
,
name
)
await
update_userinfo_dao
(
user_id
,
'real_name'
,
name
)
elif
unit
:
elif
unit
:
await
update_userinfo_dao
(
user_id
,
'unit'
,
unit
)
await
update_userinfo_dao
(
user_id
,
'unit'
,
unit
)
elif
lang
:
await
update_userinfo_dao
(
user_id
,
"lang"
,
lang
)
else
:
else
:
await
update_userinfo_dao
(
user_id
,
'job'
,
job
)
await
update_userinfo_dao
(
user_id
,
'job'
,
job
)
data
=
await
user_by_user_id
(
user_id
)
data
=
await
user_by_user_id
(
user_id
)
is_wechat
=
1
if
data
[
"wechat_id"
]
else
0
is_wechat
=
1
if
data
[
"wechat_id"
]
else
0
return
UserinfoResp
(
user_id
=
data
[
"user_id"
],
phone
=
data
[
"phone_number"
],
return
UserinfoResp
(
user_id
=
data
[
"user_id"
],
phone
=
data
[
"phone_number"
],
unit
=
data
[
"unit"
],
job
=
data
[
"job"
],
unit
=
data
[
"unit"
],
job
=
data
[
"job"
],
lang
=
data
[
"lang"
],
name
=
data
[
"real_name"
],
is_wechat
=
is_wechat
)
name
=
data
[
"real_name"
],
is_wechat
=
is_wechat
)
...
@@ -328,6 +336,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -328,6 +336,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
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
=
"微信绑定失败"
)
result
=
json
.
loads
(
res_token
)
result
=
json
.
loads
(
res_token
)
# 2.获取用户信息
# 2.获取用户信息
if
'access_token'
not
in
result
:
if
'access_token'
not
in
result
:
...
@@ -340,6 +349,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -340,6 +349,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
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
=
"微信绑定失败"
)
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
if
'openid'
in
user_info
and
'unionid'
in
user_info
:
if
'openid'
in
user_info
and
'unionid'
in
user_info
:
...
@@ -363,7 +373,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -363,7 +373,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
# await update_not_phone(user_id, unionid)
# await update_not_phone(user_id, unionid)
# 修改权限
# 修改权限
wechat_product_auth
=
await
\
wechat_product_auth
=
await
\
search_user_product_auth_dao
(
data
[
"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
}
\
...
@@ -372,7 +382,7 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -372,7 +382,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
search_user_product_auth_dao
(
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"
]
for
user_product
in
user_product_auth
}
\
for
user_product
in
user_product_auth
}
\
...
@@ -401,13 +411,13 @@ async def post_update_wechat(request, body: UpdateWechatReq):
...
@@ -401,13 +411,13 @@ async def post_update_wechat(request, body: UpdateWechatReq):
# 修改权限
# 修改权限
if
product_auth
:
if
product_auth
:
for
key
,
value
in
product_auth
.
items
():
for
key
,
value
in
product_auth
.
items
():
proxy
=
user_product_dict
.
get
(
key
)
or
wechat_product_dict
.
get
(
key
)
is_auth
=
await
search_product_auth_dao
(
user_id
,
key
)
is_auth
=
await
search_product_auth_dao
(
user_id
,
key
)
if
is_auth
:
if
is_auth
:
await
update_product_auth_dao
(
key
,
value
,
user_id
,
await
update_product_auth_dao
(
key
,
value
,
user_id
,
proxy
)
proxy
=
user_product_dict
.
get
(
key
)
or
wechat_product_dict
.
get
(
key
))
else
:
else
:
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
await
insert_product_auth_dao
(
user_id
,
key
,
value
,
proxy
)
proxy
=
user_product_dict
.
get
(
key
)
or
wechat_product_dict
.
get
(
key
))
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
(
msg
=
"微信绑定成功"
)
return
success_res
(
code
=
RET
.
wechat_error
,
msg
=
"微信绑定失败"
)
return
success_res
(
code
=
RET
.
wechat_error
,
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