Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jssuzanne
committed
Feb 6, 2018
1 parent
a3c3dd3
commit 985e55a
Showing
5 changed files
with
35 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file is a part of the AnyBlok / Pyramid project | ||
# | ||
# Copyright (C) 2018 Jean-Sebastien SUZANNE <jssuzanne@anybox.fr> | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file,You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. | ||
from pyramid.httpexceptions import HTTPUnauthorized, HTTPFound | ||
from pyramid.security import remember, forget | ||
from logging import getLogger | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def login(request): | ||
User = request.anyblok.registry.User | ||
params = User.format_login_params(request) | ||
if User.check_login(**params): | ||
login = params['login'] | ||
headers = remember(request, login) | ||
logger.info('%s is logged in', login) | ||
location = User.get_login_location_to(login, request) | ||
return HTTPFound(location=location, headers=headers) | ||
|
||
return HTTPUnauthorized(comment='Login failed') | ||
|
||
|
||
def logout(request): | ||
logger.info('%r is logged out', request.authenticated_userid) | ||
headers = forget(request) | ||
User = request.anyblok.registry.User | ||
location = User.get_logout_location_to(request) | ||
return HTTPFound(location=location, headers=headers) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters