码迷,mamicode.com
首页 > 编程语言 > 详细

python装饰器用户验。根据不同的帐号类,不同的登录方式

时间:2017-03-17 23:24:27      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:ldap   bbs   word   password   strip   wrapper   dex   *args   highlight   

import time

user,passwd=‘alex‘,‘abc123‘
def auth(auth_type):
    # print(‘auth_func:‘,auth_type)
    def outer_wrapper(func):
        def wrapper(*args, **kwargs):
            if auth_type==‘local‘:
                username = input(‘Username‘).strip()
                password = input(‘Password‘).strip()
                if user == username and passwd == password:
                    print(‘登录成功‘)
                    return func(*args, **kwargs)
                else:
                    exit(‘验证失败‘)
            elif auth_type==‘ldap‘:
                print(‘不会..‘)

        return wrapper
    return outer_wrapper

def index():
    print(‘welcome to index page‘)


@auth(auth_type="local") #home=auth()
def home():
    print(‘welcome to home page‘)
    return ‘from home‘

@auth(auth_type="ldap")
def bbs():
    print(‘welcome to bbs page‘)

index()
print(home())
bbs()

  

python装饰器用户验。根据不同的帐号类,不同的登录方式

标签:ldap   bbs   word   password   strip   wrapper   dex   *args   highlight   

原文地址:http://www.cnblogs.com/zhangzihong/p/6568950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!