Мое решение следующее:
from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember
from pyramid.security import forget
from pyramid.view import view_config
from test.security import USERS
from pyramid.security import authenticated_userid
@view_config(context='pyramid.httpexceptions.HTTPForbidden',
renderer='test:templates/forbidden.pt')
def forbidden(request):
logged_in = authenticated_userid(request)
if not logged_in:
new_url = request.application_url + '/login?came_from=' + request.url
return HTTPFound(location = new_url)
return dict(
)
@view_config(context='test.models.MyApp', name='login',
renderer='test:templates/login.pt')
def login(request):
login_url = request.resource_url(request.context, 'login')
referrer = request.url
if referrer == login_url:
referrer = '/' # never use the login form itself as came_from
came_from = request.params.get('came_from', referrer)
message = ''
login = ''
password = ''
if 'form.submitted' in request.params:
login = request.params['login']
password = request.params['password']
if USERS.get(login) == password:
headers = remember(request, login)
return HTTPFound(location = came_from,
headers = headers)
message = 'Failed login'
return dict(
message = message,
url = request.application_url + '/login',
came_from = came_from,
login = login,
password = password,
)
Может уважаемые гуру подскажут еще вариантов?