Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id_for_login before authenticate #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cone/app/browser/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def row_data(self, node):
row_data['creator'] = node.metadata.get('creator', 'unknown')
row_data['created'] = node.metadata.get('created')
row_data['modified'] = node.metadata.get('modified')
row_data['workflow_state'] = node.metadata.get('workflow_state')
return row_data

def sorted_rows(self, start, end, sort, order):
Expand Down
49 changes: 47 additions & 2 deletions src/cone/app/browser/exception.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import traceback

from cone.app.browser import render_main_template
from cone.app.browser.login import login_view
from cone.app.browser.utils import format_traceback
from cone.tile import Tile
from cone.tile import tile
from pyramid.httpexceptions import HTTPForbidden
from pyramid.httpexceptions import HTTPForbidden, HTTPBadRequest, HTTPUnauthorized
from pyramid.httpexceptions import HTTPNotFound
from pyramid.response import Response
from pyramid.view import view_config
Expand All @@ -24,7 +26,7 @@
"""


@view_config(context=Exception)
@view_config(context=Exception, accept='text/html')
def internal_server_error(request):
"""Internal server error view.
"""
Expand All @@ -50,6 +52,16 @@ def internal_server_error(request):
response.content_type = 'application/json'
return response

@view_config(
context=Exception,
accept='application/json',
renderer='json')
def json_internal_server_error(request):
request.response.status = 500
traceback.print_exc()
return {}



###############################################################################
# Unauthorized
Expand All @@ -61,6 +73,7 @@ class UnauthorizedTile(Tile):
"""


@view_config(context=HTTPUnauthorized, accept='text/html')
@view_config(context=HTTPForbidden, accept='text/html')
def forbidden_view(request):
"""Unauthorized view.
Expand All @@ -71,6 +84,10 @@ def forbidden_view(request):
return render_main_template(model, request, contenttile='unauthorized')


@view_config(
context=HTTPUnauthorized,
accept='application/json',
renderer='json')
@view_config(
context=HTTPForbidden,
accept='application/json',
Expand Down Expand Up @@ -105,3 +122,31 @@ def not_found_view(request):
def json_not_found_view(request):
request.response.status = 404
return {}

###############################################################################
# BadRequest
###############################################################################

@tile(name='bad_request', path='templates/bad_request.pt', permission='login')
class BadRequestTile(Tile):
"""Unauthorized tile.
"""


@view_config(context=HTTPBadRequest, accept='text/html')
def bad_request_view(request):
"""Unauthorized view.
"""
model = request.context
return render_main_template(model, request, contenttile='bad_request')


@view_config(
context=HTTPBadRequest,
accept='application/json',
renderer='json')
def json_bad_request_view(request):
request.response.status = 400
return {}


13 changes: 13 additions & 0 deletions src/cone/app/browser/templates/bad_request.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<tal:block xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="cone.app"
omit-tag="True">

<div>
<h1 i18n:translate="bad_request_label">BadRequest</h1>
<p i18n:translate="bad_request_text">
You have errors in your request.
</p>
</div>

</tal:block>
4 changes: 2 additions & 2 deletions src/cone/app/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def authenticate(request, login, password):
return remember(request, pid)
ugm = ugm_backend.ugm
try:
if ugm.users.authenticate(login, password):
pid = ugm.users.id_for_login(login)
pid = ugm.users.id_for_login(login)
if ugm.users.authenticate(pid, password):
return remember(request, pid)
except Exception as e:
logger.warning((
Expand Down