• 用装饰器做一个登陆系统


    主页分为四个板块:原创软件,精品软件,灌水专区,福利专区。原创软件,精品软件可以浏览,灌水专区,福利专区需要登陆后浏览,支持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('
    ' + 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()
  • 相关阅读:
    centos系统/dev/mapper/centosroot目录被占满的解决方式
    SpringBoot上如何实现文件上传 FILE
    java list 和数组直接相互转换
    vue axios.defaults.withCredentials = true
    java中局部变量需要初始化吗
    用Java实现MD5加盐
    java map 合并两个map map集合的putall_Java Map.putAll()方法:追加另一个Map对象到当前Map集合
    JSON字符串转HashMap Gson
    OO_Lab2总结博客
    采购签核 RFC bapi_po_release 淡淡
  • 原文地址:https://www.cnblogs.com/xusuns/p/8477686.html
Copyright © 2020-2023  润新知