Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
Automat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯佳佳
Automat
Commits
9bcc321c
Commit
9bcc321c
authored
Jan 18, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
25c2deeb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
24 deletions
+37
-24
myapps/pc_management/api/admin_portal.py
+24
-17
myapps/pc_management/api/business_portal.py
+9
-4
myapps/pc_management/api/machine_portal.py
+2
-1
utils/jwt_util.py
+2
-2
No files found.
myapps/pc_management/api/admin_portal.py
View file @
9bcc321c
...
@@ -207,21 +207,25 @@ def edit_user():
...
@@ -207,21 +207,25 @@ def edit_user():
if
old_phone
==
g
.
user
.
phone
:
if
old_phone
==
g
.
user
.
phone
:
admin_info
=
g
.
user
admin_info
=
g
.
user
if
level
:
admin_info
.
level
=
int
(
level
)
else
:
else
:
admin_info
=
AdminAccount
.
query
.
filter
(
AdminAccount
.
phone
==
old_phone
,
result
=
AdminService
.
get_admin_account_list
(
phone
=
old_phone
)
AdminAccount
.
level
>
g
.
user
.
level
,
if
result
[
"total_count"
]
!=
1
:
AdminAccount
.
parent_id
==
g
.
user
.
id
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
)
.
first
()
admin
=
json2obj
(
result
[
"list"
][
0
])
if
not
admin_info
:
admin_info
=
AdminAccount
.
query
.
filter_by
(
id
=
admin
.
id
)
.
first
()
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
if
not
admin_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
admin_info
.
user_name
=
user_name
if
level
and
level
>
g
.
user
.
level
:
admin_info
.
phone
=
new_phone
admin_info
.
level
=
level
admin_info
.
status
=
status
if
status
:
admin_info
.
comment
=
comment
admin_info
.
status
=
status
if
comment
:
admin_info
.
comment
=
comment
if
user_name
:
admin_info
.
user_name
=
user_name
if
new_phone
:
admin_info
.
phone
=
new_phone
if
password
:
if
password
:
admin_info
.
password
=
password
admin_info
.
password
=
password
...
@@ -230,7 +234,7 @@ def edit_user():
...
@@ -230,7 +234,7 @@ def edit_user():
business_ids
=
json_data
.
get
(
"business_ids"
,
[])
business_ids
=
json_data
.
get
(
"business_ids"
,
[])
if
business_ids
:
if
business_ids
:
AdminService
.
add_or_edit_admin_business
(
a
ccount
,
business_ids
)
AdminService
.
add_or_edit_admin_business
(
a
dmin_info
,
business_ids
)
return
BaseResponse
()
return
BaseResponse
()
...
@@ -241,8 +245,11 @@ def delete_user():
...
@@ -241,8 +245,11 @@ def delete_user():
if
not
phone
:
if
not
phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
admin_info
=
AdminAccount
.
query
.
filter
(
AdminAccount
.
phone
==
phone
,
result
=
AdminService
.
get_admin_account_list
(
phone
=
phone
)
AdminAccount
.
level
>
g
.
user
.
level
)
.
first
()
if
result
[
"total_count"
]
!=
1
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
admin
=
json2obj
(
result
[
"list"
][
0
])
admin_info
=
AdminAccount
.
query
.
filter_by
(
id
=
admin
.
id
)
.
first
()
if
not
admin_info
:
if
not
admin_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
...
...
myapps/pc_management/api/business_portal.py
View file @
9bcc321c
...
@@ -36,10 +36,15 @@ def run_business_list():
...
@@ -36,10 +36,15 @@ def run_business_list():
admin
=
g
.
user
admin
=
g
.
user
select_sql
=
"select business.business_name,business.status, business.id "
select_sql
=
"select business.business_name,business.status, business.id "
count_sql
=
"select count(business.id) as total_count"
count_sql
=
"select count(business.id) as total_count"
from_sql
=
""" from business where business.id in (select business_id from admin_business where
from_sql
=
""" from business """
admin_business.user_id = {} and admin_business.status = 1) """
.
format
(
admin
.
id
)
where_sql
=
" "
if
g
.
user
.
level
==
1
:
where_sql
=
" where 0=0 "
else
:
where_sql
=
""" where business.id in (
select business_id from admin_business where
admin_business.user_id = {} and admin_business.status = 1
)"""
.
format
(
admin
.
id
)
if
keyword
:
if
keyword
:
where_sql
+=
""" and CONCAT(business.business_name) LIKE '
%
{keyword}
%
' """
.
format
(
keyword
=
keyword
)
where_sql
+=
""" and CONCAT(business.business_name) LIKE '
%
{keyword}
%
' """
.
format
(
keyword
=
keyword
)
...
@@ -57,7 +62,7 @@ def run_business_list():
...
@@ -57,7 +62,7 @@ def run_business_list():
return_data
=
[]
return_data
=
[]
for
info
in
result
:
for
info
in
result
:
return_data
.
append
({
"business_name"
:
info
.
place
_name
,
"business_id"
:
info
.
id
,
"status"
:
info
.
status
})
return_data
.
append
({
"business_name"
:
info
.
business
_name
,
"business_id"
:
info
.
id
,
"status"
:
info
.
status
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
...
...
myapps/pc_management/api/machine_portal.py
View file @
9bcc321c
...
@@ -145,7 +145,8 @@ def run_edit_machine():
...
@@ -145,7 +145,8 @@ def run_edit_machine():
machine_model
.
device_id
=
device_id
machine_model
.
device_id
=
device_id
if
qrcode_no
:
if
qrcode_no
:
machine_model
.
qrcode_no
=
qrcode_no
machine_model
.
qrcode_no
=
qrcode_no
if
mac
:
machine_model
.
mac
=
mac
if
mac
:
machine_model
.
mac
=
mac
if
power
:
if
power
:
machine_model
.
power
=
power
machine_model
.
power
=
power
if
place_id
:
if
place_id
:
...
...
utils/jwt_util.py
View file @
9bcc321c
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 1}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 3}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
\ No newline at end of file
\ No newline at end of file
...
...
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