2023-06-29 17:52:15 +08:00
|
|
|
from fastapi import FastAPI
|
|
|
|
from pydantic import BaseModel
|
|
|
|
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-06-30 09:59:08 +08:00
|
|
|
conn = sqlite3.connect('database.sqlite')
|
|
|
|
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 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
|