Commit 62df6d07 by Aeolus

update

parent 84bc3eca
...@@ -24,7 +24,7 @@ class Config: ...@@ -24,7 +24,7 @@ class Config:
JWT_SECRET = SECRET_KEY JWT_SECRET = SECRET_KEY
TENCENT_REDIS_URL = os.getenv("TENCENT_REDIS_URL") TENCENT_REDIS_URL = os.getenv("TENCENT_REDIS_URL")
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 MAX_CONTENT_LENGTH = 16 * 1024 * 1024
# SQLALCHEMY_ECHO = True SQLALCHEMY_ECHO = True
@staticmethod @staticmethod
def init_app(app): def init_app(app):
......
...@@ -116,6 +116,7 @@ def run_create_machine_no(): ...@@ -116,6 +116,7 @@ def run_create_machine_no():
machine_model.machine_no = machine_no machine_model.machine_no = machine_no
machine_model.mac = mac machine_model.mac = mac
machine_model.hatch_number = hatch_number machine_model.hatch_number = hatch_number
machine_model.status = 1
db.session.add(machine_model) db.session.add(machine_model)
db.session.commit() db.session.commit()
return BaseResponse(data={"machine_no": machine_no}) return BaseResponse(data={"machine_no": machine_no})
......
...@@ -67,7 +67,8 @@ def create_rent(): ...@@ -67,7 +67,8 @@ def create_rent():
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
if machine.discounts_id == 1: if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first() rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE),
Rent.user_id == g.user.id).first()
if not rent: if not rent:
if len(productions) != 1: if len(productions) != 1:
return jsonify(HATCH_COUNT_ERROR) return jsonify(HATCH_COUNT_ERROR)
......
...@@ -89,11 +89,11 @@ def run_add_machine(): ...@@ -89,11 +89,11 @@ def run_add_machine():
:return: :return:
""" """
json_data = request.get_json() json_data = request.get_json()
machine_no = json_data["machine_no"] machine_no = json_data.get("machine_no", None)
address = json_data.get("address", None) address = json_data.get("address", None)
device_id = json_data.get("device_id", None) device_id = json_data.get("device_id", None)
qrcode_no = json_data.get("qrcode_no", None) qrcode_no = json_data.get("qrcode_no", None)
mac = json_data.get("mac", None) mac = json_data["mac"]
power = json_data.get("power", None) power = json_data.get("power", None)
hatch_number = json_data.get("hatch_number", None) hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None) place_id = json_data.get("place_id", None)
...@@ -112,6 +112,7 @@ def run_add_machine(): ...@@ -112,6 +112,7 @@ def run_add_machine():
machine_model.hatch_number = hatch_number machine_model.hatch_number = hatch_number
machine_model.type = type machine_model.type = type
machine_model.discounts_id = discounts_id machine_model.discounts_id = discounts_id
machine_model.status = 1
db.session.add(machine_model) db.session.add(machine_model)
admin_machine = AdminMachine() admin_machine = AdminMachine()
......
#!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": 'XXTM000015'}, 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": 'XXTM000015'}, 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment