本文整理汇总了Python中pyramid.security.remember方法的典型用法代码示例。如果您正苦于以下问题:Python security.remember方法的具体用法?Python security.remember怎么用?Python security.remember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.security
的用法示例。
在下文中一共展示了security.remember方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_view
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def login_view(request):
deform_static.need()
search_path = ('myShop/templates/deform/',)
renderer = deform.ZPTRendererFactory(search_path)
schema = LoginFormSchema(validator=password_validator)
form = deform.Form(schema, buttons=('submit',), renderer=renderer)
if 'submit' in request.POST:
try:
appstruct = form.validate(request.POST.items())
except deform.ValidationFailure, e:
return {
'title': 'login',
'form': e.render()
}
user = appstruct['login']
headers = remember(request, user.id)
return HTTPFound(location='/', headers=headers)
示例2: login
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def login(self, **params):
self._json_params.update(params)
next = self._query_params.get('next', '')
if self.request.path in next:
next = '' # never use the login form itself as next
unauthorized_url = self._query_params.get('unauthorized', None)
success, user = self.Model.authenticate_by_password(
self._json_params)
if success:
pk_field = user.pk_field()
headers = remember(self.request, getattr(user, pk_field))
if next:
raise JHTTPFound(location=next, headers=headers)
else:
return JHTTPOk('Logged in', headers=headers)
if user:
if unauthorized_url:
return JHTTPUnauthorized(location=unauthorized_url+'?error=1')
raise JHTTPUnauthorized('Failed to Login.')
else:
raise JHTTPNotFound('User not found')
示例3: register
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def register(self):
""" Register a new user by POSTing all required data.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
user, created = self.Model.create_account(self._json_params)
if user.api_key is None:
raise JHTTPBadRequest('Failed to generate ApiKey for user')
if not created:
raise JHTTPConflict('Looks like you already have an account.')
self.request._user = user
headers = remember(self.request, user.username)
return JHTTPOk('Registered', headers=headers)
示例4: claim_token
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def claim_token(self, **params):
"""Claim current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
self._json_params.update(params)
success, self.user = self.Model.authenticate_by_password(
self._json_params)
if success:
headers = remember(self.request, self.user.username)
return JHTTPOk('Token claimed', headers=headers)
if self.user:
raise JHTTPUnauthorized('Wrong login or password')
else:
raise JHTTPNotFound('User not found')
示例5: validate_user
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def validate_user(context, request, appstruct):
user = get_or_create_user(request, appstruct)
valid = user and (has_role(user=user, role=('SiteAdmin', )) or
'active' in getattr(user, 'state', []))
headers = None
if valid:
request.session.pop('novaideo.came_from', None)
headers = remember(request, get_oid(user))
request.registry.notify(
LoggedIn(
user.email, user,
context, request))
user.last_connection = datetime.datetime.now(tz=pytz.UTC)
if hasattr(user, 'reindex'):
user.reindex()
return user, valid, headers
示例6: render
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def render(self):
if not self.user.is_sudoer(self.session):
log.info("user '%s' tried to access sudo but is not authorized" %
self.user.login)
return HTTPFound(location=route_url('home', self.request))
req = self.request
if req.method == 'POST' and 'continue' in req.params:
headers = None
target_id = int(req.params.get('sudo', self.user.id))
if target_id != self.user.id:
target = User.by_id(self.session, target_id)
if not target:
errors = ['Cannot find user with id %d' % target_id]
self.request.session.flash('error;%s' % ','.join(errors))
log.info("user '%s' will sudo to user '%s'" %
(self.user.login, target.login))
headers = remember(self.request, target.login)
return HTTPFound(location=route_url('home', self.request),
headers=headers)
return {'user': self.user}
示例7: login_cookie_view
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def login_cookie_view(request):
headers = remember(request, 1)
return Response(status=200, headers=headers, body="OK")
示例8: reset_token
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def reset_token(self, **params):
""" Reset current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
response = self.claim_token(**params)
if not self.user:
return response
self.user.api_key.reset_token()
headers = remember(self.request, self.user.username)
return JHTTPOk('Registered', headers=headers)
示例9: admin_sign_in
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def admin_sign_in(self):
if self.request.method == "POST":
admin_user = self.request.registry.settings["admin_user"]
admin_secret = self.request.registry.settings["admin_secret"]
username = self.request.POST.get("username", "").strip()
password = self.request.POST.get("password", "").strip()
if username == admin_user and password == admin_secret:
headers = remember(self.request, admin_user)
url = self.request.route_url("admin")
return HTTPFound(url, headers=headers)
else:
# make potential brute forcing non-feasible
gevent.sleep(0.5)
return {}
示例10: login
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def login(request):
form = forms.FormValidator(forms.UserLogin())
if request.method == 'POST' and form.validate(request.POST):
user = request.db.query(models.User).filter_by(email=form['email'].strip(), password=sha1(form['password'].encode('utf-8')).hexdigest()).first()
if user is not None:
security.remember(request, user.id)
request.user = user
url = request.route_url('overview')
return HTTPFound(location=url)
request.session.flash('Benutzername oder Passwort sind falsch.', queue='errors')
return {'form': form, 'user': security.authenticated_userid(request)}
示例11: update
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def update(self):
self.execute(None)
try:
navbars = generate_listing_menu(
self.request, self.context,
template=DEFAUL_LISTING_ACTIONS_TEMPLATE)
except ObjectRemovedException:
#Log in if the invitation is accepted
if hasattr(self.context, 'person'):
person = self.context.person
headers = remember(self.request, get_oid(person))
self.request.registry.notify(
LoggedIn(person.email, person,
self.context, self.request))
root = getSite()
return HTTPFound(
location=self.request.resource_url(root),
headers=headers)
return HTTPFound(self.request.resource_url(getSite(), ''))
user = get_current()
values = {
'invitation': self.context,
'menu_body': navbars['menu_body'],
'primary_menu_body': navbars['primary_menu_body'],
'state': get_states_mapping(
user, self.context, self.context.state[0]),}
result = {}
body = self.content(args=values, template=self.template)['body']
item = self.adapt_item(body, self.viewid)
item['messages'] = navbars['messages']
item['isactive'] = navbars['isactive']
result.update(navbars['resources'])
result['coordinates'] = {self.coordinates: [item]}
return result
示例12: redirect
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def redirect(self, context, request, **kw):
person = kw['person']
headers = remember(request, get_oid(person))
request.registry.notify(LoggedIn(person.email, person,
context, request))
return HTTPFound(location=request.resource_url(context),
headers=headers)
示例13: login
# 需要导入模块: from pyramid import security [as 别名]
# 或者: from pyramid.security import remember [as 别名]
def login(context, request):
login_data = json.loads(request.body.decode())
login = login_data.get('login', None)
password = login_data.get('password', None)
token = login_data.get('token', None)
logged_user = None
if token:
logged_user = auth_user(token, request)
if login and password:
novaideo_catalog = find_catalog('novaideo')
dace_catalog = find_catalog('dace')
identifier_index = novaideo_catalog['identifier']
object_provides_index = dace_catalog['object_provides']
query = object_provides_index.any([IPerson.__identifier__]) &\
identifier_index.any([login])
users = list(query.execute().all())
user = users[0] if users else None
valid_check = user and user.check_password(password)
if valid_check and \
(has_role(user=user, role=('SiteAdmin', )) or \
'active' in getattr(user, 'state', [])):
logged_user = user
if getattr(logged_user, 'api_token', None) is None:
logged_user.api_token = uuid.uuid4().hex
if logged_user:
headers = remember(request, get_oid(logged_user))
request.registry.notify(LoggedIn(login, logged_user, context, request))
logged_user.last_connection = datetime.datetime.now(tz=pytz.UTC)
request.response.headerlist.extend(headers)
if hasattr(logged_user, 'reindex'):
logged_user.reindex()
return {
'status': True,
'token': logged_user.api_token
}
return {
'status': False,
'token': None
}