websoft9/appmanage/api/service/db.py

33 lines
1.2 KiB
Python
Raw Normal View History

2023-06-29 17:52:15 +08:00
from fastapi import FastAPI
from pydantic import BaseModel
2023-06-30 10:34:44 +08:00
from api.exception.command_exception import CommandException
from api.utils import const
2023-06-29 17:52:15 +08:00
from api.model.user import User
import sqlite3
2023-06-30 09:59:08 +08:00
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
2023-06-29 17:52:15 +08:00
def AppUpdateUser(user_name, password):
2023-07-20 09:07:05 +08:00
conn = sqlite3.connect('/usr/src/app/database.sqlite')
2023-06-30 09:59:08 +08:00
cursor = conn.cursor()
cursor.execute("UPDATE user SET password=? WHERE user_name=?", ( password,user_name,))
2023-06-29 17:52:15 +08:00
conn.commit()
2023-06-30 09:59:08 +08:00
conn.close()
2023-06-29 17:52:15 +08:00
def AppSearchUsers(user_type):
2023-06-30 10:41:09 +08:00
if user_type == None or user_type == "undefine":
raise CommandException(const.ERROR_CLIENT_PARAM_BLANK, "This plugin is blank!", "This plugin is blank!")
if user_type != "nginx" and user_type != "portainer":
2023-06-30 10:34:44 +08:00
raise CommandException(const.ERROR_CLIENT_PARAM_NOTEXIST, "This plugin doesn't exist!", "This plugin doesn't exist!")
2023-06-30 09:59:08 +08:00
conn = sqlite3.connect('/usr/src/app/database.sqlite')
conn.row_factory = dict_factory
cursor = conn.cursor()
cursor.execute("SELECT user_name,password,nick_name FROM user WHERE user_type=?", (user_type,))
rows = cursor.fetchone()
conn.close()
return rows