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
78d26505
Commit
78d26505
authored
Jan 18, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8e668185
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
myapps/pc_management/api/machine_portal.py
+12
-6
service/admin_service.py
+4
-2
utils/jwt_util.py
+2
-2
No files found.
myapps/pc_management/api/machine_portal.py
View file @
78d26505
...
@@ -15,8 +15,10 @@ from flask import Blueprint, g, request, jsonify
...
@@ -15,8 +15,10 @@ from flask import Blueprint, g, request, jsonify
from
config.commen_config
import
DISCOUNTS_TYPES
from
config.commen_config
import
DISCOUNTS_TYPES
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
AdminMachine
,
Machine
,
AdminAccount
,
AdminBusiness
from
models.models
import
AdminMachine
,
Machine
,
AdminAccount
,
AdminBusiness
from
service.admin_service
import
AdminService
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
ACCOUNT_NOT_EXISTS_ERROR
,
ADMIN_BUSINESS_NOT_EXIST
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
ACCOUNT_NOT_EXISTS_ERROR
,
ADMIN_BUSINESS_NOT_EXIST
from
utils.my_response
import
BaseResponse
from
utils.my_response
import
BaseResponse
from
utils.mytools
import
json2obj
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -212,14 +214,16 @@ def run_distribute_machine():
...
@@ -212,14 +214,16 @@ def run_distribute_machine():
user_id
=
json_data
[
"user_id"
]
user_id
=
json_data
[
"user_id"
]
business_id
=
json_data
[
"business_id"
]
business_id
=
json_data
[
"business_id"
]
user
=
AdminAccount
.
query
.
filter_by
(
id
=
user_id
,
parent_id
=
g
.
user
.
id
,
status
=
1
)
.
first
(
)
result
=
AdminService
.
get_admin_account_list
(
user_id
=
user_id
)
if
not
user
:
if
result
[
"total_count"
]
!=
1
:
return
jsonify
(
ACCOUNT_NOT_EXISTS_ERROR
)
return
jsonify
(
ACCOUNT_NOT_EXISTS_ERROR
)
admin_info
=
json2obj
(
result
[
"list"
][
0
])
admin_business
=
AdminBusiness
.
query
.
filter_by
(
user_id
=
g
.
user
.
id
,
business_id
=
business_id
,
status
=
1
)
.
first
()
admin_business
=
AdminBusiness
.
query
.
filter_by
(
user_id
=
g
.
user
.
id
,
business_id
=
business_id
,
status
=
1
)
.
first
()
if
not
admin_business
:
if
not
admin_business
:
return
jsonify
(
ADMIN_BUSINESS_NOT_EXIST
)
return
jsonify
(
ADMIN_BUSINESS_NOT_EXIST
)
return_machine_no
=
[]
for
i
in
machine_nos
:
for
i
in
machine_nos
:
admin_machines
=
AdminMachine
.
query
.
filter_by
(
user_id
=
g
.
user
.
id
,
machine_no
=
i
,
status
=
1
)
.
first
()
admin_machines
=
AdminMachine
.
query
.
filter_by
(
user_id
=
g
.
user
.
id
,
machine_no
=
i
,
status
=
1
)
.
first
()
if
not
admin_machines
:
if
not
admin_machines
:
...
@@ -228,12 +232,14 @@ def run_distribute_machine():
...
@@ -228,12 +232,14 @@ def run_distribute_machine():
if
not
machine
:
if
not
machine
:
continue
continue
insert_sql
=
" insert into admin_machine (user_id, user_no, machine_no) values "
insert_sql
=
" insert into admin_machine (user_id, user_no, machine_no) values "
for
i
in
machine_nos
:
insert_sql
+=
"('{}','{}','{}'),"
.
format
(
user
.
id
,
user
.
user_no
,
i
)
insert_sql
+=
"('{}','{}','{}'),"
.
format
(
admin_info
.
id
,
admin_info
.
user_no
,
i
)
insert_sql
=
insert_sql
[:
-
1
]
insert_sql
=
insert_sql
[:
-
1
]
insert_sql
+=
" ON DUPLICATE KEY UPDATE status = 1"
insert_sql
+=
" ON DUPLICATE KEY UPDATE status = 1"
db
.
session
.
execute
(
insert_sql
)
db
.
session
.
execute
(
insert_sql
)
machine
.
business_id
=
business_id
if
admin_info
.
level
==
4
:
machine
.
business_id
=
business_id
db
.
session
.
commit
()
db
.
session
.
commit
()
return_machine_no
.
append
(
i
)
return
BaseResponse
(
data
=
{
"add_machine_nos"
:
machine_nos
})
return
BaseResponse
(
data
=
{
"add_machine_nos"
:
return_machine_no
})
service/admin_service.py
View file @
78d26505
...
@@ -62,7 +62,7 @@ class AdminService(object):
...
@@ -62,7 +62,7 @@ class AdminService(object):
db
.
session
.
commit
()
db
.
session
.
commit
()
@staticmethod
@staticmethod
def
get_admin_account_list
(
phone
=
None
,
keyword
=
None
,
page
=
None
,
page_size
=
None
):
def
get_admin_account_list
(
user_id
=
None
,
phone
=
None
,
keyword
=
None
,
page
=
None
,
page_size
=
None
):
"""
"""
:return:
:return:
...
@@ -87,8 +87,10 @@ class AdminService(object):
...
@@ -87,8 +87,10 @@ class AdminService(object):
and admin_account.level > {level}
and admin_account.level > {level}
"""
.
format
(
user_id
=
g
.
user
.
id
,
level
=
g
.
user
.
level
)
"""
.
format
(
user_id
=
g
.
user
.
id
,
level
=
g
.
user
.
level
)
if
user_id
:
where_sql
+=
" and admin_account.id = '{id}'"
.
format
(
id
=
user_id
)
if
phone
:
if
phone
:
where_sql
+=
" and phone =
{phone}
"
.
format
(
phone
=
phone
)
where_sql
+=
" and phone =
'{phone}'
"
.
format
(
phone
=
phone
)
if
keyword
:
if
keyword
:
where_sql
+=
"""
where_sql
+=
"""
...
...
utils/jwt_util.py
View file @
78d26505
#!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)
#!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": 4}, 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