parent
154e19d46e
commit
04abb48e26
@ -0,0 +1,53 @@
|
||||
import json
|
||||
|
||||
class MysqlDatabases:
|
||||
def __init__(self):
|
||||
self.users = json.loads(open('users.json',mode='r',encoding='utf-8').read())
|
||||
self.cake = json.loads(open('cake.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,'登录成功'
|
||||
return False,'登录失败,密码不存在'
|
||||
|
||||
def check_register(self,username):
|
||||
for user in self.users:
|
||||
if username == user['username']:
|
||||
return False, '注册失败,用户已存在'
|
||||
return True, '注册成功'
|
||||
|
||||
|
||||
def all(self):
|
||||
return self.cake
|
||||
|
||||
def insert(self,student):
|
||||
self.cake.append(student)
|
||||
|
||||
def delete_by_username(self,name):
|
||||
for student in self.cake:
|
||||
print(student)
|
||||
if student['name'] == name:
|
||||
self.cake.remove(student)
|
||||
return True,f'{name}删除成功'
|
||||
return False,f'{name}不存在'
|
||||
def search_by_username(self,name):
|
||||
for student in self.cake:
|
||||
if student['name'] == name:
|
||||
return True,student
|
||||
return False,f'{name}不存在'
|
||||
|
||||
def update(self,stu):
|
||||
for student in self.cake:
|
||||
if student['name'] == stu['name']:
|
||||
student.update(stu)
|
||||
return True,f''
|
||||
return False,f'{stu["name"]}不存在'
|
||||
|
||||
|
||||
db = MysqlDatabases()
|
||||
|
||||
if __name__ =='__main__':
|
||||
print(db.check_login('admin','123456'))
|
||||
print(db.all())
|
Loading…
Reference in new issue