本文整理汇总了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()
示例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()
示例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)
示例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()