用裝飾器做一個登陸系統
阿新 • • 發佈:2018-03-12
賬號 nbsp else HR return 查重 user 軟件 hone
主頁分為四個板塊:原創軟件,精品軟件,灌水專區,福利專區。原創軟件,精品軟件可以瀏覽,灌水專區,福利專區需要登陸後瀏覽,支持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()
用裝飾器做一個登陸系統