zoukankan      html  css  js  c++  java
  • 装饰器添加模拟用户登陆页面(终极版)

    基础的只支持在本地验证

    ###这是终极版本,基础版本需要输入两次验证,现在这个可以说是只验证一次把
    ##第五步是判断了
    user,password = "caicai","13421731046"
    
    def auth(auth_type):#在这之前的参数只能掉来第二层了func
        def ouder_wrapper(func):
            def wrapper(*args, **kwargs):
                if auth_type == "local":
                    userInput = input("user:").strip()
                    passwordInput = input("password:").strip()
                    if userInput == user and passwordInput == password:
                        print("33[32;1m Welcome to 33[0m")
                        ##用户登陆完成后应该要执行它之前的功能了
                        res = func(*args, **kwargs)
                        return res
                    else:
                        exit("33[31;1m login failure 33[0m")
                elif auth_type == "lapl":
                    print("ww")
                    print()
            return wrapper
        return ouder_wrapper
    
    
    def index():
        print("welcome to index page")
    ###auth_type = "local"这个参数是直接传到第一次函数嵌套
    @auth(auth_type = "local")##我现在要做只要登陆一次就行的(1)
    
    def home():
        print("welcome to home page")
    ##又传进去一个参数,怎么搞定,嘻嘻,多加一层函数嵌套咯ouder_wrapper
    @auth(auth_type = "lapl")##需要验证的加上,这里传的参数是用在判断上
    def bbs():
        print("welcome to bbs page")
    
    
    ##调用
    index()
    home()
    bbs()
    以上内容作为课堂笔记,如有雷同,请联系于我
  • 相关阅读:
    高可靠JAVA项目
    C语言JS引擎
    星际争霸,FF反作弊对战平台
    【转】ffluos编译
    〓经典文字武侠游戏 书剑 书剑江湖自由度超高!公益服!〓
    全局解释器锁GIL
    创建多线程Thread
    线程的简述Thread
    进程池的回调函数callback
    进程池的同步与异步用法Pool
  • 原文地址:https://www.cnblogs.com/ArtisticMonk/p/8932285.html
Copyright © 2011-2022 走看看