本文整理汇总了Python中pyramid.request.Request.validated['user']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.validated['user']方法的具体用法?Python Request.validated['user']怎么用?Python Request.validated['user']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.validated['user']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_login_name
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated['user'] [as 别名]
def validate_login_name(context, request: Request):
"""Validate the user name of a login request.
If valid and activated, the user object is added as 'user' to
`request.validated`.
"""
name = request.validated['name']
locator = request.registry.getMultiAdapter((context, request),
IUserLocator)
user = locator.get_user_by_login(name)
if user is None:
_add_no_such_user_or_wrong_password_error(request)
else:
request.validated['user'] = user
示例2: validate_login_email
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated['user'] [as 别名]
def validate_login_email(context, request: Request):
"""Validate the email address of a login request.
If valid, the user object is added as 'user' to
`request.validated`.
"""
email = request.validated['email']
locator = request.registry.getMultiAdapter((context, request),
IUserLocator)
normalized_email = email.lower()
user = locator.get_user_by_email(normalized_email)
if user is None:
_add_no_such_user_or_wrong_password_error(request)
else:
request.validated['user'] = user
示例3: validate_activation_path
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated['user'] [as 别名]
def validate_activation_path(context, request: Request):
"""Validate the user name of a login request.
If valid and activated, the user object is added as 'user' to
`request.validated`.
"""
path = request.validated['path']
locator = request.registry.getMultiAdapter((context, request),
IUserLocator)
user = locator.get_user_by_activation_path(path)
registry = request.registry
if user is None or _activation_time_window_has_expired(user, registry):
error = error_entry('body', 'path',
'Unknown or expired activation path')
request.errors.append(error)
else:
user.activate()
request.validated['user'] = user
if user is not None:
user.activation_path = None # activation path can only be used once
示例4: validate_activation_path
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated['user'] [as 别名]
def validate_activation_path(context, request: Request):
"""Validate the user name of a login request.
If valid and activated, the user object is added as 'user' to
`request.validated`.
"""
path = request.validated['path']
locator = request.registry.getMultiAdapter((context, request),
IUserLocator)
user = locator.get_user_by_activation_path(path)
error = error_entry('body', 'path', 'Unknown or expired activation path')
if user is None:
request.errors.append(error)
elif is_older_than(user, days=8):
request.errors.append(error)
user.activation_path = None
else:
user.activate()
user.activation_path = None
request.validated['user'] = user
event = ResourceSheetModified(user, IUserBasic, request.registry, {},
{}, request)
request.registry.notify(event) # trigger reindex activation_path index