本文整理汇总了Python中pyramid.security.unauthenticated_userid函数的典型用法代码示例。如果您正苦于以下问题:Python unauthenticated_userid函数的具体用法?Python unauthenticated_userid怎么用?Python unauthenticated_userid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unauthenticated_userid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:mathcamp,项目名称:steward_palantir,代码行数:35,代码来源:smartmail.py
示例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
开发者ID:Thisisdotme,项目名称:thisis.me,代码行数:29,代码来源:oauth_googleplus.py
示例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
开发者ID:ochriste,项目名称:geoportailv3,代码行数:31,代码来源:authentication.py
示例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()
开发者ID:Lytol,项目名称:PomStack,代码行数:7,代码来源:helpers.py
示例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()
开发者ID:adidas,项目名称:pyramid-test,代码行数:7,代码来源:auth.py
示例6: get_user
def get_user(request):
userid = unauthenticated_userid(request)
try:
user = User.by_username(userid)
except (MultipleResultsFound, NoResultFound):
user = None
return user
开发者ID:cewing,项目名称:pyramid-react-journal,代码行数:7,代码来源:utils.py
示例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()
开发者ID:bertjwregeer,项目名称:defcne,代码行数:60,代码来源:auth.py
示例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
开发者ID:ryanfox,项目名称:pyramid_cas,代码行数:30,代码来源:views.py
示例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))
开发者ID:Rygbee,项目名称:pyramid_simpleauth,代码行数:30,代码来源:hooks.py
示例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()
开发者ID:jayd3e,项目名称:MonkeyBall,代码行数:7,代码来源:request.py
示例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
开发者ID:Thisisdotme,项目名称:thisis.me,代码行数:30,代码来源:oauth_foursquare.py
示例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.'}
开发者ID:jajadinimueter,项目名称:rest_toolkit,代码行数:7,代码来源:error.py
示例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))
开发者ID:Debjeeti20,项目名称:bodhi,代码行数:7,代码来源:__init__.py
示例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
开发者ID:Pylons,项目名称:pylonshq,代码行数:7,代码来源:request.py
示例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)
开发者ID:hadoukn,项目名称:hadoukn,代码行数:7,代码来源:security.py
示例16: getMainPageLoggedIn
def getMainPageLoggedIn(request):
# check if user has priviliges and if yes allow him to modify
groups = groupfinder(unauthenticated_userid(request), request)
with_modify = False
if groups and 'g:moderator' in groups or 'g:admin' in groups:
with_modify = True
return {'welcomepage':'off', 'with_modify':with_modify}
开发者ID:slub,项目名称:vkviewer,代码行数:7,代码来源:GetIndexPages.py
示例17: casLogin
def casLogin(request):
"""
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')
return HTTPFound(location=request.route_url('home'),headers=headers)
else:
return HTTPFound(location='/not-allowed')
开发者ID:aaguirre,项目名称:pyramid_cas,代码行数:27,代码来源:views.py
示例18: tm_tween
def tm_tween(request):
if 'repoze.tm.active' in request.environ:
# don't handle txn mgmt if repoze.tm is in the WSGI pipeline
return handler(request)
if activate is not None:
if not activate(request):
return handler(request)
manager = getattr(request, 'tm', None)
if manager is None: # pragma: no cover (pyramid < 1.4)
manager = create_tm(request)
request.tm = manager
number = attempts
if annotate_user:
if hasattr(request, 'unauthenticated_userid'):
userid = request.unauthenticated_userid
else: # pragma no cover (for pyramid < 1.5)
from pyramid.security import unauthenticated_userid
userid = unauthenticated_userid(request)
else:
userid = None
while number:
number -= 1
try:
manager.begin()
# make_body_seekable will copy wsgi.input if necessary,
# otherwise it will rewind the copy to position zero
if attempts != 1:
request.make_body_seekable()
t = manager.get()
if userid:
userid = native_(userid, 'utf-8')
t.setUser(userid, '')
try:
t.note(native_(request.path_info, 'utf-8'))
except UnicodeDecodeError:
t.note("Unable to decode path as unicode")
response = handler(request)
if manager.isDoomed():
raise AbortResponse(response)
if commit_veto is not None:
veto = commit_veto(request, response)
if veto:
raise AbortResponse(response)
manager.commit()
return response
except AbortResponse as e:
manager.abort()
return e.response
except:
exc_info = sys.exc_info()
try:
retryable = manager._retryable(*exc_info[:-1])
manager.abort()
if (number <= 0) or (not retryable):
reraise(*exc_info)
finally:
del exc_info # avoid leak
开发者ID:Rafails,项目名称:MyCalc,代码行数:60,代码来源:__init__.py
示例19: get_user
def get_user(request):
userid = unauthenticated_userid(request)
if userid is not None:
return DBSession.query(User).filter(User.id == userid).first()
return None
开发者ID:cicide,项目名称:Flex-Voicemail,代码行数:7,代码来源:lib.py
示例20: user
def user(self):
from .models.user import User
userid = unauthenticated_userid(self)
if self.path.startswith('/admin'):
return User.admin_by_id(userid)
if userid is not None:
return User.get_by_id(userid)
开发者ID:paweldudzinski,项目名称:foodel,代码行数:7,代码来源:db.py
注:本文中的pyramid.security.unauthenticated_userid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论