Browse Source

added error view for expired token

rework
Holger Frey 7 years ago
parent
commit
7668ecfc88
  1. 2
      ordr/__init__.py
  2. 2
      ordr/models/__init__.py
  3. 2
      ordr/resources/__init__.py
  4. 2
      ordr/schemas/__init__.py
  5. 2
      ordr/security.py
  6. 0
      ordr/templates/errors/404_file_not_found.jinja2
  7. 14
      ordr/templates/errors/410_token_expiry.jinja2
  8. 35
      ordr/templates/errors/registration_verify.jinja2
  9. 2
      ordr/views/__init__.py
  10. 18
      ordr/views/errors.py
  11. 11
      tests/views/errors.py

2
ordr/__init__.py

@ -5,7 +5,7 @@ from pyramid.session import SignedCookieSessionFactory @@ -5,7 +5,7 @@ from pyramid.session import SignedCookieSessionFactory
__version__ = '0.0.1'
def main(global_config, **settings):
def main(global_config, **settings): # pragma: no cover
''' This function returns a Pyramid WSGI application. '''
config = Configurator(settings=settings)

2
ordr/models/__init__.py

@ -48,7 +48,7 @@ def get_tm_session(session_factory, transaction_manager): @@ -48,7 +48,7 @@ def get_tm_session(session_factory, transaction_manager):
return dbsession
def includeme(config):
def includeme(config): # pragma: no cover
'''
Initialize the model for a Pyramid app.

2
ordr/resources/__init__.py

@ -40,7 +40,7 @@ class RootResource: @@ -40,7 +40,7 @@ class RootResource:
return child_class(name=key, parent=self)
def includeme(config):
def includeme(config): # pragma: no cover
'''
Initialize the resources for traversal in a Pyramid app.

2
ordr/schemas/__init__.py

@ -43,7 +43,7 @@ class CSRFSchema(colander.Schema): @@ -43,7 +43,7 @@ class CSRFSchema(colander.Schema):
return deform.Form(schema, **settings)
def includeme(config):
def includeme(config): # pragma: no cover
'''
Initialize the form schemas

2
ordr/security.py

@ -74,7 +74,7 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'): @@ -74,7 +74,7 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'):
return '\n'.join(config_lines)
def includeme(config):
def includeme(config): # pragma: no cover
''' initializing authentication, authorization and password hash settings
Activate this setup using ``config.include('ordr.security')``.

0
ordr/templates/errors/404.jinja2 → ordr/templates/errors/404_file_not_found.jinja2

14
ordr/templates/errors/410_token_expiry.jinja2

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
{% extends "ordr:templates/layout.jinja2" %}
{% block title %} Ordr | Error {% endblock title %}
{% block content %}
<div class="row justify-content-md-center mt-3">
<div class="col-8">
<h1 class="mt-3">An Error has occured</h1>
<p class="mt-4">The link you've clicked has expired.</p>
<small class="text-secondary">410 - Gone</small>
</div>
</div>
{% endblock content %}

35
ordr/templates/errors/registration_verify.jinja2

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
{% extends "ordr:templates/layout.jinja2" %}
{% block title %} Ordr | Registration {% endblock title %}
{% block content %}
<div class="row justify-content-md-center mt-3">
<div class="col-6">
<h1>Registration</h1>
</div>
</div>
<div class="row justify-content-md-center mt-3">
<div class="col-2">
<p class="text-secondary">
Step 1: Registration
</p>
</div>
<div class="col-2">
<p class="text-primary">
Step 2: Validate Email
</p>
</div>
<div class="col-2">
<p class="text-secondary">
Step 3: Finished
</p>
</div>
</div>
<div class="row justify-content-md-center mt-3">
<div class="col-6">
<h3>Verify Your Email Address</h3>
<p class="mt-3">To complete the registration process an email has been sent to you.</p>
<p>Please follow the link in the email to verify your address and complete the registration process.</p>
</div>
</div>
{% endblock content %}

2
ordr/views/__init__.py

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
''' views (sub) package for ordr '''
def includeme(config):
def includeme(config): # pragma: no cover
'''
Initialize the views in a Pyramid app.

18
ordr/views/errors.py

@ -1,8 +1,22 @@ @@ -1,8 +1,22 @@
from pyramid.view import notfound_view_config
from pyramid.view import notfound_view_config, view_config
from ordr.models.account import TokenExpired
@notfound_view_config(renderer='ordr:templates/errors/404.jinja2')
@notfound_view_config(
renderer='ordr:templates/errors/404_file_not_found.jinja2'
)
def notfound_view(context, request):
''' display a file not found page '''
request.response.status = 404
return {}
@view_config(
context=TokenExpired,
renderer='ordr:templates/errors/410_token_expiry.jinja2'
)
def token_expired(context, request):
''' display page describing expired token '''
request.response.status = 410
return {}

11
tests/views/errors.py

@ -10,3 +10,14 @@ def test_404(): @@ -10,3 +10,14 @@ def test_404():
assert result == {}
assert request.response.status == '404 Not Found'
def test_token_expired():
''' test the token expired found view '''
from ordr.views.errors import token_expired
request = DummyRequest()
result = token_expired(None, request)
assert result == {}
assert request.response.status == '410 Gone'