本文整理汇总了Python中pyramid.security.unauthenticated_userid函数的典型用法代码示例。如果您正苦于以下问题:Python unauthenticated_userid函数的具体用法?Python unauthenticated_userid怎么用?Python unauthenticated_userid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unauthenticated_userid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, request, check, normalized_retcode, results, **kwargs):
if normalized_retcode == 0:
title = 'RESOLVED'
action = 'succeeded'
elif normalized_retcode == 1:
title = 'WARNING'
action = 'failed'
else:
title = 'ERROR'
action = 'failed'
if len(results) == 1:
target = results[0].minion
else:
target = "%d minions" % len(results)
subject = "[%s] %s on %s" % (title, check.name, target)
if kwargs.get('marked_resolved'):
minions = [result.minion for result in results]
body = ("%s marked resolved by %s on %s" %
(check.name, unauthenticated_userid(request),
', '.join(minions)))
else:
body = "%s %s on\n" % (check.name, action)
for result in results:
body += (" %s %d time%s\n" % (result.minion, result.count,
's' if result.count > 1 else
''))
if result.stdout:
body += 'STDOUT:\n' + result.stdout
if result.stderr:
body += 'STDERR:\n' + result.stderr
request.subreq('mail', subject=subject, body=body, mail_to=self.mail_to)
示例2: googleplus_callback
def googleplus_callback(request):
error_msg = None
author_id = unauthenticated_userid(request)
code = request.params.get('code')
if not code:
error = request.params.get('error')
log.error('Google+ oauth failed: %s' % error)
raise Exception(error)
# let's exchange the authorization code for an access token and a refresh token
query_args = {'code': code,
'client_id': tim_config['oauth'][SERVICE]['key'],
'client_secret': tim_config['oauth'][SERVICE]['secret'],
'redirect_uri': request.route_url('googleplus_callback'),
'grant_type': 'authorization_code'}
try:
r = requests.post(tim_config['oauth'][SERVICE]['oauth_exchange_url'], data=query_args)
r.raise_for_status()
json_dict = r.json
except requests.exceptions.RequestException, e:
log.error(e)
raise e
示例3: get_user_from_request
def get_user_from_request(request):
from c2cgeoportal.models import DBSession, Role
class O(object):
pass
username = unauthenticated_userid(request)
if username is not None:
user = O()
user.id = 0
user.username = username
user.email = None
connector = get_ldap_connector(request)
cm = connector.manager
# 0 means 'Tous publics'
roletheme = 0
with cm.connection() as conn:
result = conn.search_s("ou=portail,dc=act,dc=lu", ldap.SCOPE_SUBTREE, "(login=%s)" % username)
if len(result) == 1:
if "roleTheme" in result[0][1]:
roletheme = result[0][1]["roleTheme"][0]
if "mail" in result[0][1]:
user.mail = result[0][1]["mail"][0]
if "sn" in result[0][1]:
user.sn = result[0][1]["sn"][0]
user.role = DBSession.query(Role).filter_by(id=roletheme).one()
user.functionalities = []
return user
示例4: user
def user(self):
session = DBSession()
user_email = unauthenticated_userid(self)
if user_email is not None:
# this should return None if the user doesn't exist
# in the database
return session.query(User).filter(User.email==user_email).first()
示例5: get_user
def get_user(request):
'''fetches the user. Used to attach a user object to the request'''
user = unauthenticated_userid(request)
if user is not None:
return DBSession.query(User).filter(User.user == user).first()
else:
return DBSession.query(User).filter(User.user == User.VISITOR).first()
示例6: get_user
def get_user(request):
userid = unauthenticated_userid(request)
try:
user = User.by_username(userid)
except (MultipleResultsFound, NoResultFound):
user = None
return user
示例7: current_user
def current_user(request):
"""
This is added to the request as an attribute named "user"
The function takes care of everything and caches various results so that
for each time we call `user_groups` we don't rerun the database queries
unnecessarily. It is highly unlikely that in the milliseconds it takes to
render the page that the user is going to lose access to a particular
resource.
"""
class UserData:
pass
def _user_nonexistent():
udata = UserData()
udata.username = None
udata.user = None
udata.ticket = None
udata.groups = None
return udata
def _user_exists(user, ticket, groups):
udata = UserData()
udata.username = user.disp_uname
udata.user = user
udata.ticket = ticket
udata.groups = groups
return udata
userid = security.unauthenticated_userid(request)
# Check to see if any tokens are set
if 'REMOTE_USER_TOKENS' in request.environ:
cur_ticket = [x for x in request.environ['REMOTE_USER_TOKENS'] if 'tkt_' in x]
cur_ticket = cur_ticket[0][4:] if len(cur_ticket) == 1 else None
# If we don't get a ticket, we return that the user is non-existent
if cur_ticket is None:
return _user_nonexistent()
# Find the user by looking up the ticket/username
ticket = UserTickets.find_ticket_username(cur_ticket, userid)
# If the ticket has been removed, we unauth the user
if ticket is None:
return _user_nonexistent()
user = ticket.user
# Load up all the groups that the user is in
user_groups = ['userid:' + unicode(user.id)]
user_groups.extend(['group:' + grp.name for grp in user.groups])
# Return a valid user containing data
return _user_exists(user, ticket, user_groups)
return _user_nonexistent()
示例8: caslogin
def caslogin(request, return_url=None):
"""
Cas login and user challenger view
"""
service = cas.getserviceurl(request)
username = unauthenticated_userid(request)
if username is None:
ticket = request.GET.get('ticket')
if ticket is None:
return cas.sendtoservice(request)
username = cas.verifycas20(request, ticket, service)
if username is None:
return 'no user'
settings = request.registry.settings
if 'pyramid_cas.callback.get_user' in settings:
callable = settings['pyramid_cas.callback.get_user']
module = callable.split('.')[0] + '.' + callable.split('.')[1]
caller = sys.modules[module]
method = getattr(caller, callable.split('.')[2])
user = method(username, request)
else:
user = username
headers = remember(request, user, max_age='86400')
# fall back to setting from config file if return_url isn't provided
redirect_to = return_url or request.route_url(settings['pyramid_cas.redirect_route'])
return HTTPFound(location=redirect_to, headers=headers)
else:
raise HTTPForbidden
示例9: get_is_authenticated
def get_is_authenticated(request):
"""Has this ``request`` been made by an authenticated user?
Setup::
>>> from mock import Mock
>>> from pyramid_simpleauth import hooks
>>> _unauthenticated_userid = hooks.unauthenticated_userid
>>> hooks.unauthenticated_userid = Mock()
>>> mock_request = Mock()
When the request is not authenticated, returns ``False``::
>>> hooks.unauthenticated_userid.return_value = None
>>> get_is_authenticated(mock_request)
False
When the request is authenticated, returns ``True``::
>>> hooks.unauthenticated_userid.return_value = 1234
>>> get_is_authenticated(mock_request)
True
Teardown::
>>> hooks.unauthenticated_userid = _unauthenticated_userid
"""
return bool(unauthenticated_userid(request))
示例10: player
def player(self):
session = self.db
user_id = unauthenticated_userid(self)
if user_id is not None:
# this should return None if the user doesn't exist
# in the database
return session.query(Player).filter_by(id=user_id).first()
示例11: foursquare_callback
def foursquare_callback(request):
error_msg = None
author_id = unauthenticated_userid(request)
code = request.params.get('code')
if not code:
error = request.params.get('error')
raise Exception('Error authenticating user with Foursquare: {error}'.format(error=error))
# let's get the acces_token
queryArgs = urllib.urlencode([('client_id', tim_config['oauth'][SERVICE]['key']),
('client_secret', tim_config['oauth'][SERVICE]['secret']),
('grant_type', 'authorization_code'),
('redirect_uri', request.route_url('foursquare_callback')),
('code', code)])
url = tim_config['oauth'][SERVICE]['access_token_url'].format(args=queryArgs)
try:
r = requests.get(url)
r.raise_for_status()
json_dict = r.json
except requests.exceptions.RequestException, e:
log.error(e)
raise e
示例12: forbidden
def forbidden(request):
if unauthenticated_userid(request):
request.response.status_int = 403
return {'message': 'You are not allowed to perform this action.'}
else:
request.response.status_int = 401
return {'message': 'You must login to perform this action.'}
示例13: get_user
def get_user(request):
from bodhi.models import User
userid = unauthenticated_userid(request)
if userid is not None:
user = request.db.query(User).filter_by(name=unicode(userid)).first()
# Why munch? https://github.com/fedora-infra/bodhi/issues/473
return munchify(user.__json__(request=request))
示例14: user
def user(self):
if not self.path_info.startswith('/static'):
username = unauthenticated_userid(self)
if username:
return User.by_username(username)
else:
return None
示例15: get_user
def get_user(request):
db = request.db
api_key = unauthenticated_userid(request)
if api_key is not None:
# this should return None if the user doesn't exist
# in the database
return User.by_api_key(db, api_key)