parent
cc87c76446
commit
52422f1e6c
@ -0,0 +1,55 @@
|
||||
import json
|
||||
|
||||
|
||||
class MysqlDatabases:
|
||||
def __init__(self):
|
||||
self.users = json.loads(open('users.json', mode='r', encoding='utf-8').read())
|
||||
self.bkuser = json.loads(open('bkuser.json', mode='r', encoding='utf-8').read())
|
||||
|
||||
def check_login(self, username, password):
|
||||
for user in self.users:
|
||||
if username == user['username']:
|
||||
if password == user['password']:
|
||||
return True, '登录成功'
|
||||
else:
|
||||
return False, '登录失败,密码不存在'
|
||||
return False, '登录失败,用户不存在'
|
||||
|
||||
def all(self):
|
||||
return self.bkuser
|
||||
|
||||
def insert(self, bk):
|
||||
self.bkuser.append(bk)
|
||||
|
||||
def delete_by_username(self, name):
|
||||
for bk in self.bkuser:
|
||||
print(bk)
|
||||
if bk['name'] == name:
|
||||
self.bkuser.remove(bk)
|
||||
return True, f'{name}删除用户成功'
|
||||
return False, f'{name}用户不存在'
|
||||
|
||||
def search_by_username(self, name):
|
||||
for bk in self.bkuser:
|
||||
print(bk)
|
||||
if bk['name'] == name:
|
||||
return True, bk
|
||||
return False, f'{name}用户不存在'
|
||||
|
||||
def update(self, bk1):
|
||||
for bk in self.bkuser:
|
||||
if bk['name'] == bk1['name']:
|
||||
bk.update(bk1)
|
||||
return True, f'{bk1["name"]}用户修改数据成功'
|
||||
return False, f'{bk1["name"]}用户不存在'
|
||||
|
||||
def register(self,user1):
|
||||
pass
|
||||
|
||||
|
||||
db = MysqlDatabases()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print(db.check_login('admin','123456'))
|
||||
# print(db.all())
|
||||
print(db.search_by_username('张三'))
|
Loading…
Reference in new issue