当前位置: 首页>>代码示例>>Python>>正文


Python User.authenticate方法代码示例

本文整理汇总了Python中rfk.database.base.User.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python User.authenticate方法的具体用法?Python User.authenticate怎么用?Python User.authenticate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rfk.database.base.User的用法示例。


在下文中一共展示了User.authenticate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doConnect

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import authenticate [as 别名]
def doConnect(data):
    """handles a connect from liquidsoap
    
    Keyword arguments:
    data -- list of headers
    
    """
    logger.info('connect request %s' % (json.dumps(data),))
    try:
        auth = data['Authorization'].strip().split(' ')
        if auth[0].lower() == 'basic':
            username, password = base64.b64decode(auth[1]).split(':', 1)
            if username == 'source':
                username, password = password.split(username_delimiter, 1)
        else:
            raise ValueError
        user = User.authenticate(username, password)
        if user.get_setting(code='use_icy'):
            if 'ice-genre' in data:
                user.set_setting(data['ice-genre'],code='icy_show_genre')
            if 'ice-name' in data:
                user.set_setting(data['ice-name'],code='icy_show_name')
            if 'ice-description' in data:
                user.set_setting(data['ice-description'],code='icy_show_description')
        show = init_show(user)
        rfk.database.session.commit()
        logger.info('accepted connect for %s' %(user.username,))
        print user.user
    except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError):
        logger.info('rejected connect')
        kick()
开发者ID:alphabernd,项目名称:PyRfK,代码行数:33,代码来源:liquidsoaphandler.py

示例2: doAuth

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import authenticate [as 别名]
def doAuth(username, password):
    """authenticates the user
    this function will also disconnect the current user
    if the user to be authenticated has a show registered.
    if that happened this function will print false to the
    user since we need a graceperiod to actually disconnect
    the other user.
    
    Keyword arguments:
    username
    password
    
    """
    if username == 'source':
        username, password = password.split(username_delimiter)
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            if kick():
                logger.info('kicking user')
                sys.stdout.write('false')
                return
        logger.info('accepted auth for %s' %(username,))
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('rejected auth for %s (invalid password)' %(username,))
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('rejected auth for %s (invalid user)' %(username,))
        sys.stdout.write('false')
    rfk.database.session.commit()
开发者ID:alphabernd,项目名称:PyRfK,代码行数:34,代码来源:liquidsoaphandler.py

示例3: doConnect

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import authenticate [as 别名]
def doConnect(data):
    """Handles a connect from liquidsoap
    
    Keyword arguments:
        data -- list of headers
    """
    publish_show = False

    # better to not store any passwords in our logs
    safe_dump = data.copy()
    safe_dump.pop('Authorization', None)
    logger.info('doConnect: connect request %s' % (json.dumps(safe_dump),))

    rfk.database.session.commit()
    try:
        auth = data['Authorization'].strip().split(' ')
        if auth[0].lower() == 'basic':
            try:
                username, password = base64.b64decode(auth[1]).decode('utf-8').split(':', 1)
            except UnicodeDecodeError:
                username, password = base64.b64decode(auth[1]).decode('latin-1').split(':', 1)
            if username == 'source':
                username, password = password.split(username_delimiter, 1)
        else:
            raise ValueError
        user = User.authenticate(username, password)
        if user.get_setting(code='use_icy'):
            if 'ice-genre' in data:
                user.set_setting(data['ice-genre'], code='icy_show_genre')
            if 'ice-name' in data:
                user.set_setting(data['ice-name'], code='icy_show_name')
            if 'ice-description' in data:
                user.set_setting(data['ice-description'], code='icy_show_description')
        show = init_show(user)
        publish_show = show.show
        logger.info('doConnect: accepted connect for %s' % (user.username,))
        print user.user
    except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError):
        logger.info('doConnect: rejected connect, initiate kick...')
        kick()

    rfk.database.session.commit()
    publish.show_change(publish_show)
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:45,代码来源:liquidsoaphandler.py

示例4: doAuth

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import authenticate [as 别名]
def doAuth(username, password):
    """Authenticates a user

    This function will also disconnect the current user
    if the user to be authenticated has a show registered.
    If that happens this function will print false to the
    user since we need a grace period to actually disconnect
    the other user. (Which means that the user has to reconnect.)
    
    Keyword arguments:
        - username
        - password
    """

    if username == 'source':
        try:
            username, password = password.split(username_delimiter)
        except ValueError:
            pass
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            logger.info('doAuth: cleaning harbor because of planned show')
            if kick():
                sys.stdout.write('false')
                logger.info('doAuth: harbor is now clean, reconnect pl0x')
                rfk.database.session.commit()
                return
            else:
                logger.info('doAuth: harbor was empty, go ahead')
        logger.info('doAuth: accepted auth for %s' % username)
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('doAuth: rejected auth for %s (invalid password)' % username)
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('doAuth: rejected auth for %s (invalid user)' % username)
        sys.stdout.write('false')

    rfk.database.session.commit()
开发者ID:NinjaTune,项目名称:PyRfK,代码行数:43,代码来源:liquidsoaphandler.py


注:本文中的rfk.database.base.User.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。