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
9c59730d
Commit
9c59730d
authored
Oct 16, 2021
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
33c765f0
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
13 deletions
+87
-13
myapps/sukang24h/api/tallyman_portal.py
+65
-8
service/tallyman_service.py
+20
-3
utils/error_code.py
+0
-0
utils/jwt_util.py
+2
-2
No files found.
myapps/sukang24h/api/tallyman_portal.py
View file @
9c59730d
...
@@ -8,9 +8,10 @@ from config.base_config import MONGO_DATABASE_URI
...
@@ -8,9 +8,10 @@ from config.base_config import MONGO_DATABASE_URI
from
config.commen_config
import
LOGIN_TYPE
from
config.commen_config
import
LOGIN_TYPE
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
TallymanAccount
,
TallymanMachine
,
TallymanLoginRecord
from
models.models
import
TallymanAccount
,
TallymanMachine
,
TallymanLoginRecord
,
Machine
from
service.tallyman_service
import
TallymanService
from
service.tallyman_service
import
TallymanService
from
utils.error_code
import
TALLYMAN_ACCOUNT_EXIST
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
PASSWORD_ERROR
from
utils.error_code
import
TALLYMAN_ACCOUNT_EXIST
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
PASSWORD_ERROR
,
\
TALLYMAN_ACCOUNT_NOT_EXIST
from
utils.jwt_util
import
verify_jwt
,
generate_jwt
from
utils.jwt_util
import
verify_jwt
,
generate_jwt
from
utils.my_response
import
BaseResponse
from
utils.my_response
import
BaseResponse
...
@@ -28,31 +29,79 @@ def test():
...
@@ -28,31 +29,79 @@ def test():
@tallyman_route.route
(
'/edit_password'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/edit_password'
,
methods
=
[
'GET'
,
'POST'
])
def
run_tallyman_edit_password
():
def
run_tallyman_edit_password
():
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
user_name
=
json_data
.
get
(
'name'
,
None
)
password
=
json_data
.
get
(
'password'
,
None
)
password
=
json_data
.
get
(
'password'
,
None
)
tallyman_info
=
g
.
user
tallyman_info
=
g
.
user
if
not
tallyman_info
:
if
not
tallyman_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
return
jsonify
(
TALLYMAN_ACCOUNT_NOT_EXIST
)
if
password
:
tallyman_info
.
password
=
password
db
.
session
.
add
(
tallyman_info
)
db
.
session
.
commit
()
return
BaseResponse
()
@tallyman_route.route
(
'/edit_account'
,
methods
=
[
'GET'
,
'POST'
])
def
run_tallyman_edit_account
():
admin
=
g
.
user
if
g
.
user
.
level
!=
1
:
return
jsonify
({
"error_code"
:
"500"
,
"error_message"
:
"没有权限"
})
json_data
=
request
.
get_json
()
phone
=
json_data
.
get
(
'phone'
,
None
)
user_name
=
json_data
.
get
(
'name'
,
None
)
password
=
json_data
.
get
(
'password'
,
None
)
machine_list
=
json_data
.
get
(
'machine_list'
,
None
)
tallyman_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
not
tallyman_info
:
return
jsonify
(
TALLYMAN_ACCOUNT_NOT_EXIST
)
if
user_name
:
if
user_name
:
tallyman_info
.
user_name
=
user_name
tallyman_info
.
user_name
=
user_name
if
password
:
if
password
:
tallyman_info
.
password
=
password
tallyman_info
.
password
=
password
db
.
session
.
add
(
tallyman_info
)
db
.
session
.
add
(
tallyman_info
)
db
.
session
.
commit
()
db
.
session
.
commit
()
if
not
machine_list
:
return
BaseResponse
()
old_machine_list
=
Machine
.
query
.
join
(
TallymanMachine
,
TallymanMachine
.
machine_no
==
Machine
.
machine_no
)
.
filter
(
TallymanMachine
.
user_id
==
tallyman_info
.
id
)
.
all
()
old_machine_dict
=
{}
for
i
in
old_machine_list
:
old_machine_dict
[
i
.
machine_no
]
=
i
for
i
in
machine_list
:
if
old_machine_dict
.
get
(
i
):
old_machine_dict
[
i
]
.
status
=
1
db
.
session
.
add
(
old_machine_dict
[
i
])
else
:
model
=
TallymanMachine
()
model
.
user_id
=
tallyman_info
.
id
model
.
machine_no
=
i
model
.
status
=
1
db
.
session
.
add
(
model
)
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
@tallyman_route.route
(
'/add_account'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/add_account'
,
methods
=
[
'GET'
,
'POST'
])
def
add_user
():
def
add_user
():
admin
=
g
.
user
if
g
.
user
.
level
!=
1
:
return
jsonify
({
"error_code"
:
"500"
,
"error_message"
:
"没有权限"
})
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
user_name
=
json_data
[
'name'
]
if
'name'
in
json_data
else
'SSW'
user_name
=
json_data
[
'name'
]
if
'name'
in
json_data
else
'SSW'
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
level
=
int
(
json_data
[
'level'
])
if
'level'
in
json_data
else
2
level
=
int
(
json_data
[
'level'
])
if
'level'
in
json_data
else
2
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
None
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
None
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
machine_list
=
json_data
.
get
(
"machine_list"
,
[])
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
tallyman
:
if
tallyman
:
...
@@ -78,7 +127,6 @@ def add_user():
...
@@ -78,7 +127,6 @@ def add_user():
db
.
session
.
add
(
tallyman
)
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
db
.
session
.
commit
()
machine_list
=
json_data
.
get
(
"machine_list"
,
[])
if
not
machine_list
:
if
not
machine_list
:
return
BaseResponse
()
return
BaseResponse
()
...
@@ -101,14 +149,14 @@ def delete_user():
...
@@ -101,14 +149,14 @@ def delete_user():
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
not
tallyman
:
if
not
tallyman
:
return
BaseResponse
()
return
BaseResponse
()
tallyman
.
status
=
-
1
db
.
session
.
add
(
tallyman
)
agent_spot_info
=
TallymanMachine
.
query
.
filter_by
(
user_id
=
tallyman
.
id
)
.
all
()
agent_spot_info
=
TallymanMachine
.
query
.
filter_by
(
user_id
=
tallyman
.
id
)
.
all
()
for
info
in
agent_spot_info
:
for
info
in
agent_spot_info
:
info
.
status
=
-
1
info
.
status
=
-
1
db
.
session
.
add
(
info
)
db
.
session
.
add
(
info
)
tallyman
.
status
=
-
1
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
...
@@ -155,7 +203,16 @@ def run_tallyman_login():
...
@@ -155,7 +203,16 @@ def run_tallyman_login():
@tallyman_route.route
(
'/machine_list'
,
methods
=
[
'GET'
,
'POST'
])
@tallyman_route.route
(
'/machine_list'
,
methods
=
[
'GET'
,
'POST'
])
def
get_tallyman_machine_list
():
machine_info
=
TallymanService
.
get_machine_list
(
g
.
user
)
return
BaseResponse
(
data
=
machine_info
)
@tallyman_route.route
(
'/machine_info'
,
methods
=
[
'GET'
,
'POST'
])
def
get_agent_module_list
():
def
get_agent_module_list
():
machine_info
=
TallymanService
.
get_machine_info
(
g
.
user
)
json_data
=
request
.
get_json
()
machine_no
=
json_data
[
"machine_no"
]
machine_info
=
TallymanService
.
get_machine_info
(
g
.
user
,
machine_no
)
return
BaseResponse
(
data
=
machine_info
)
return
BaseResponse
(
data
=
machine_info
)
service/tallyman_service.py
View file @
9c59730d
...
@@ -8,10 +8,14 @@ logger = logging.getLogger(__name__)
...
@@ -8,10 +8,14 @@ logger = logging.getLogger(__name__)
class
TallymanService
(
object
):
class
TallymanService
(
object
):
@classmethod
@classmethod
def
get_machine_
info
(
cls
,
tallyman
):
def
get_machine_
list
(
cls
,
tallyman
):
machine_infos
=
Machine
.
query
(
Machine
)
.
join
(
TallymanMachine
,
machine_infos
=
Machine
.
query
.
join
(
TallymanMachine
,
TallymanMachine
.
machine_no
==
Machine
.
machine_no
)
.
filter
(
TallymanMachine
.
machine_no
==
Machine
.
machine_no
)
.
filter
(
user_id
=
tallyman
.
id
,
status
=
1
)
.
all
()
TallymanMachine
.
user_id
==
tallyman
.
id
,
TallymanMachine
.
status
==
1
)
.
all
()
# machine_infos = db.session.query(Machine).join(TallymanMachine,
# TallymanMachine.machine_no == Machine.machine_no).filter(
# TallymanMachine.user_id == tallyman.id, TallymanMachine.status == 1).all()
return_data
=
[]
return_data
=
[]
for
tmp_machine
in
machine_infos
:
for
tmp_machine
in
machine_infos
:
...
@@ -24,3 +28,16 @@ class TallymanService(object):
...
@@ -24,3 +28,16 @@ class TallymanService(object):
Hatch
.
status
==
2
)
.
count
()
Hatch
.
status
==
2
)
.
count
()
return_data
.
append
(
cur_machine
)
return_data
.
append
(
cur_machine
)
return
return_data
return
return_data
@classmethod
def
get_machine_info
(
cls
,
tallyman
,
machine_no
):
machine_info
=
Machine
.
query
.
join
(
TallymanMachine
,
TallymanMachine
.
machine_no
==
Machine
.
machine_no
)
.
filter
(
TallymanMachine
.
user_id
==
tallyman
.
id
,
TallymanMachine
.
status
==
1
,
Machine
.
machine_no
==
machine_no
)
.
first
()
if
not
machine_info
:
return
None
utils/error_code.py
View file @
9c59730d
This diff is collapsed.
Click to expand it.
utils/jwt_util.py
View file @
9c59730d
#!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": 'SK000001'}, 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": 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)
\ 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