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()
    以上内容作为课堂笔记,如有雷同,请联系于我
  • 相关阅读:
    Hdu 1257最少拦截系统
    删除mysql__转
    sql 入门的小例子熟悉一下_这可是一个转转转贴 :)
    header 用法_转
    java_json 转换 文件在file中
    javascript_php 正则匹配 转
    mysql 忘记密码转_kinghu
    php 通用下载
    明天就是新年开始
    翻译 有助于程序命名
  • 原文地址:https://www.cnblogs.com/ArtisticMonk/p/8932285.html
Copyright © 2011-2022 走看看