Commit 9bcc321c by Aeolus

update

parent 25c2deeb
......@@ -207,21 +207,25 @@ def edit_user():
if old_phone == g.user.phone:
admin_info = g.user
if level:
admin_info.level = int(level)
else:
admin_info = AdminAccount.query.filter(AdminAccount.phone == old_phone,
AdminAccount.level > g.user.level,
AdminAccount.parent_id == g.user.id
).first()
result = AdminService.get_admin_account_list(phone=old_phone)
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:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
admin_info.user_name = user_name
admin_info.phone = new_phone
if level and level > g.user.level:
admin_info.level = level
if status:
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:
admin_info.password = password
......@@ -230,7 +234,7 @@ def edit_user():
business_ids = json_data.get("business_ids", [])
if business_ids:
AdminService.add_or_edit_admin_business(account, business_ids)
AdminService.add_or_edit_admin_business(admin_info, business_ids)
return BaseResponse()
......@@ -241,8 +245,11 @@ def delete_user():
if not phone:
return BaseResponse(**PHONE_NOT_NULL_ERROR)
admin_info = AdminAccount.query.filter(AdminAccount.phone == phone,
AdminAccount.level > g.user.level).first()
result = AdminService.get_admin_account_list(phone=phone)
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:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
......
......@@ -36,10 +36,15 @@ def run_business_list():
admin = g.user
select_sql = "select business.business_name,business.status, business.id "
count_sql = "select count(business.id) as total_count"
from_sql = """ from business where business.id in (select business_id from admin_business where
admin_business.user_id = {} and admin_business.status = 1) """.format(admin.id)
from_sql = """ from business """
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:
where_sql += """ and CONCAT(business.business_name) LIKE '%{keyword}%' """.format(keyword=keyword)
......@@ -57,7 +62,7 @@ def run_business_list():
return_data = []
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})
......
......@@ -145,7 +145,8 @@ def run_edit_machine():
machine_model.device_id = device_id
if qrcode_no:
machine_model.qrcode_no = qrcode_no
if mac: machine_model.mac = mac
if mac:
machine_model.mac = mac
if power:
machine_model.power = power
if place_id:
......
#!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
#!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
......
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