CPI Ordering System (the old version)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

72 lines
1.7 KiB

from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember, forget
7 years ago
from pyramid.view import view_config
from ordr.models import User
7 years ago
@view_config(
context='ordr.resources.RootResource',
7 years ago
permission='view',
)
def welcome(context, request):
next = 'orders' if request.user else 'login'
redirect_to = request.resource_url(context, next)
return HTTPFound(redirect_to)
@view_config(
context='ordr.resources.RootResource',
name='faq',
permission='view',
renderer='ordr:templates/pages/faq.jinja2'
)
def faq(context, request):
return {}
@view_config(
context='ordr.resources.RootResource',
name='login',
request_method='GET',
permission='view',
renderer='ordr:templates/pages/login.jinja2',
)
def login(context, request):
7 years ago
return {'loginerror': False}
7 years ago
@view_config(
context='ordr.resources.RootResource',
name='login',
request_method='POST',
7 years ago
permission='view',
renderer='ordr:templates/pages/login.jinja2',
7 years ago
)
def check_login(context, request):
username = request.POST.get('username')
password = request.POST.get('password')
user = (
request.dbsession
.query(User)
.filter_by(username=username)
.first()
)
if user and user.is_active and user.check_password(password):
headers = remember(request, user.id)
return HTTPFound(request.resource_url(request.root), headers=headers)
7 years ago
return {'loginerror': True}
@view_config(
context='ordr.resources.RootResource',
name='logout',
permission='view'
)
def logout(context, request):
''' log out of an user '''
headers = forget(request)
return HTTPFound(request.resource_url(request.root), headers=headers)