用户持久化

it2025-02-07  5

import sys from datetime import datetime users = [] login_user = {} articles = [] def init(): pass def main(): print("------------------欢迎进入博客系统------------------\n") print("\t\t1、用户注册\n") print("\t\t2、用户登录\n") print("\t\t3、退出系统\n") print("------------------------------------------------------\n") return input("请输入您的操作:") def main_blog(): print("------------------欢迎进入博客系统------------------\n") print("\t\t1、发布博客\n") print("\t\t2、查看自己博客\n") print("\t\t3、删除自己博客\n") print("\t\t4、回到上一级\n") print("------------------------------------------------------\n") return input("请输入您的操作:") def is_exists(username): for u in users: if u.get("username") == username: return True return False def check_reg(username, password, comfirm_pass): if username is None or username.strip() == "": print("用户名不能为空") return False if is_exists(username): print("该用户名称已经存在,请重新注册") return False if password == None or password.strip() == "" or len(password) < 3: print("对不起,密码不能为空或者长度不能小于3位") return False if password.strip() != comfirm_pass.strip(): print("对不起,两次密码不一致") return False return True while True: choice = main() if choice == "1": while True: username = input("请输入用户名:") password = input("请输入密码:") comfirm_pass = input("请再次输入密码:") break elif choice == "2": username = input("请输入用户名:") password = input("请输入密码:") while True: choice = main_blog() if choice == "1": title = input("请输入博客标题:") content = input("请输入博客内容:") article = {} article["title"] = title article['content'] = content article["publish_time"] = datetime.now() article["modify_time"] = datetime.now() article["author"] = login_user.get("username") articles.append(article) print("当前所有文章是:") print(articles) elif choice == "2": print("查看自己博客") print(articles) elif choice == "3": print("删除博客") else: break else: print("登录失败,用户名或者密码错误,请重新登录") else: yes = input("您确定要退出系统?(yes):") if yes.lower() == "yes": sys.exit()
最新回复(0)