更新 database_manager.py
parent
1511faecde
commit
c180dad115
|
|
@ -2,6 +2,7 @@ import pymysql
|
|||
from db.connection import MySQLPool
|
||||
import bcrypt
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
def __init__(self):
|
||||
# 使用MySQLPool初始化数据库连接池
|
||||
|
|
@ -44,12 +45,23 @@ class DatabaseManager:
|
|||
return self.execute(sql, data)
|
||||
|
||||
def valid_login(self, phone_number, password_attempt):
|
||||
# SQL查询获取用户的哈希密码
|
||||
sql = "SELECT password FROM user WHERE phone_number=%s LIMIT 1"
|
||||
# SQL查询获取用户的哈希密码,身份和状态
|
||||
sql = "SELECT password, identity, status FROM user WHERE phone_number=%s LIMIT 1"
|
||||
result = self.fetch(sql, (phone_number,))
|
||||
if result:
|
||||
stored_hash = result[0]['password'] # 假设结果是密码字段
|
||||
identity = result[0]['identity'] # 用户身份
|
||||
status = result[0]['status'] # 用户状态
|
||||
|
||||
# 使用bcrypt进行密码验证
|
||||
if bcrypt.checkpw(password_attempt.encode('utf-8'), stored_hash.encode('utf-8')):
|
||||
return True # 密码匹配,登录成功
|
||||
return False # 密码不匹配或用户不存在,登录失败
|
||||
# 密码匹配,返回登录成功,身份和状态
|
||||
return {'valid': True, 'identity': identity, 'status': status}
|
||||
|
||||
# 密码不匹配或用户不存在,返回登录失败
|
||||
return {'valid': False}
|
||||
|
||||
def get_meun(self, role):
|
||||
sql = "SELECT menu_name FROM menu_items WHERE role=%s ORDER BY `order`"
|
||||
result = self.fetch(sql, (role,))
|
||||
return result
|
||||
|
|
|
|||
Reference in New Issue