EnglishPal/app/model/user.py

32 lines
963 B
Python
Raw Normal View History

2023-03-23 17:09:25 +08:00
from model import *
from Login import md5
2023-04-18 21:50:54 +08:00
from pony import orm
2023-03-23 17:09:25 +08:00
def get_users():
with db_session:
return User.select().order_by(User.name)[:]
2024-07-04 10:09:27 +08:00
def get_user_by_username(username: object) -> object:
2023-03-31 13:39:28 +08:00
with db_session:
user = User.select(name=username)
if user:
return user.first()
2023-03-23 17:09:25 +08:00
2023-04-18 21:50:54 +08:00
def insert_user(username, password, start_date, expiry_date):
with db_session:
user = User(name=username, password=password, start_date=start_date, expiry_date=expiry_date)
orm.commit()
2024-07-04 10:09:27 +08:00
def update_password_by_username(username: object, password: object = "123456") -> object:
2023-03-23 17:09:25 +08:00
with db_session:
user = User.select(name=username)
if user:
user.first().password = md5(username + password)
def update_expiry_time_by_username(username, expiry_time="20230323"):
with db_session:
user = User.select(name=username)
if user:
user.first().expiry_date = expiry_time
2024-07-04 10:09:27 +08:00