用装饰器做一个登陆系统
主页分为四个板块:原创软件,精品软件,灌水专区,福利专区。原创软件,精品软件可以浏览,灌水专区,福利专区需要登陆后浏览,支持qq登陆和本地登陆两种方式,用户系统支持增删改查功能(学习完正则之后再修改),需要留用户名密码手机三个 选项。
logeinflag = False def rand(): # 四位数字验证码 import random randlist = [] for i in range(4): c = random.randint(48, 57) randlist.append(chr(c)) b = ''.join(randlist) print(b) userrand = input('输入验证码').strip() if userrand != b: print('验证码错误') rand() return True def reg(): # 注册 global logeinflag, username, userpwd, userphone username = input('输入用户名').strip() userpwd = input('输入密码').strip() userphone = input('输入电话').strip() if rand() and same(): with open('base.txt', 'a+', encoding='utf-8') as regtxt: new = '^^'.join([username, userpwd, userphone]) regtxt.write('\n' + new) logeinflag = True print('注册成功,已经登录') main() else: return reg() return True def same(): # 查重 with open('base.txt', 'r', encoding='utf-8') as sametxt: for i in sametxt: if username == i.split('^^')[0]: print('用户名已经被占用,请重新输入') return False return True def outer(func): def logein(): # 登陆 global logeinflag if logeinflag == False: choicelogein = input('选择登陆方式:1.qq 2.本地账号 3.注册') if choicelogein == '1': with open('qq.txt', 'r', encoding='utf-8') as qq: username = input('输入用户名').strip() userpwd = input('输入密码').strip() for i in qq: if username == i.split('^^')[0] and userpwd == i.split('^^')[1]: logeinflag = True print('登陆成功') main() else: print('用户名密码错误') logein() if choicelogein == '2': with open('base.txt', 'r', encoding='utf-8') as base: username = input('输入用户名').strip() userpwd = input('输入密码').strip() for i in base: if username == i.split('^^')[0] and userpwd == i.split('^^')[1]: logeinflag = True print('登陆成功') main() else: print('用户名密码错误') logein() if choicelogein == '3': reg() func() return logein def soft(): print('欢迎进入精品软件区') print('浏览选择1,回帖选择2') choiceitme = input('请输入选择的序号:') if choiceitme == '1': print('浏览内容') if choiceitme == '2': print('回帖内容') return main() def orig(): print('欢迎进入原创软件区') print('浏览选择1,回帖选择2') choiceitme = input('请输入选择的序号:') if choiceitme == '1': print('浏览内容') if choiceitme == '2': print('回帖内容') return main() @outer def enter(): print('欢迎进入灌水专区') print('浏览选择1,回帖选择2') choiceitme = input('请输入选择的序号:') if choiceitme == '1': print('浏览内容') if choiceitme == '2': print('回帖内容') return main() @outer def welf(): print('欢迎进入福利专区') print('浏览选择1,回帖选择2') choiceitme = input('请输入选择的序号:') if choiceitme == '1': print('浏览内容') if choiceitme == '2': print('回帖内容') return main() def main(): print(' Choice Zone '.center(50, '*')) print(''' 1.精品软件 2.原创软件 3.灌水专区 4.福利专区 ''') choicezone = input('请输入选择的序号:') if choicezone == '1': soft() if choicezone == '2': orig() if choicezone == '3': enter() if choicezone == '4': welf() main()