Code Monkey home page Code Monkey logo

django-ticketoffice's Introduction

django-ticketoffice

django-ticketoffice provides one-shot authentication (a.k.a. temporary credentials) utilities for Django. It lets you create and manage tickets that allow users to perform one action on the website. As an example, Django could use it for the "password reset" action, where users authenticate using a temporary token.

Example

Restrict some URL to guests with valid invitation tickets:

from django.conf.urls import patterns, url
from django_ticketoffice.decorators import invitation_required, stamp_invitation

@invitation_required(place='louvre', purpose='visit')
@stamp_invitation  # Mark invitation as used right **after** view execution.
def visit_louvre(request):
    ticket = request.cache['invitation']  # Set by `invitation_required`.
    return 'Welcome to the Louvre museum {guest}'.format(
        guest=ticket.data['first_name'])

urlpatterns = patterns('', url('^louvre$', visit_louvre, name='louvre'))

Create and deliver tickets for this resource:

from django.utils.timezone import now
from django_ticketoffice.models import Ticket

ticket = Ticket(place='louvre', purpose='visit')
ticket.set_password('I love Paris')  # Encrypted in database.
ticket.expiry_datetime = now() + timedelta(days=5)  # Optional.
ticket.data = {'first_name': 'Léonard'}  # Optional.
ticket.save()

credentials = {'uuid': ticket.uuid, 'password': 'I love Paris'}
visit_url = reverse('louvre') + '?' + urlencode(credentials)

django-ticketoffice focuses on authentication. It does not send invitation emails. You may check django-mail-factory about sending emails.

Project status

django-ticketoffice is, at the moment, a proof-of-concept: it delivers basic features in order to create tickets and to use them in views. It works (you can use it), but it may lack some features (ideas are welcome), and it may change (improve) quite a bit. That said, maintainers will take care of release notes and migrations.

See also vision, roadmap and alternatives to get a better overview of project status.

Resources

django-ticketoffice's People

Contributors

aleksandr-shtaub avatar benoitbryon avatar toopy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-ticketoffice's Issues

invitation_required decorator does not support UUID with dashes

Something like this should do the trick...

diff --git a/django_ticketoffice/decorators.py b/django_ticketoffice/decorators.py
index 225a1fb..50abfb0 100644
--- a/django_ticketoffice/decorators.py
+++ b/django_ticketoffice/decorators.py
@@ -68,7 +68,10 @@ def invitation_required(place=u'', purpose=u'',
                 invitation_uuid = request.session['invitation']
             except KeyError:  # No invitation in session, check credentials.
                 if request.GET:
-                    form = TicketAuthenticationForm(data=request.GET,
+                    data = request.GET.dict()
+                    if '-' in data['uuid']:
+                        data['uuid'] = data['uuid'].replace('-', '')
+                    form = TicketAuthenticationForm(data=data,
                                                     place=place,
                                                     purpose=purpose)
                     if form.is_valid():

class-based invitation_required decorator is easy to override

Currently, invitation_required decorator accepts some views as arguments: forbidden, unauthorized and login.

Should be:

  • invitation_required is a class-based decorator (see http://tech.novapost.fr/python-class-based-decorators-en.html as an example)
  • invitation_required accepts only two arguments: place and purpose
  • actions to perform when forbidden, unauthorized or login are methods of invitation_required class => they are easy to override them; they have access to decorator's internal context (such as invitation ticket instance).

Tickets have a "max_usage" counter, or "unlimited_usage" boolean

Primary use case is to provide unlimited usage.
Could be implemented with a simple boolean ("unlimited_usage" or something like that).
Could also be implemented with a counter which is decremented each time the ticket is used. A "-1" value would mean "unlimited_usage".

django-ticketoffice provides web API to manage ticket

See docs/about/vision.
As software built on top of Django, it should not be over-complicated for django-ticketoffice to provide a web API to manage tickets and authenticate.
Of course, such a feature must be configurable (at least, developers must be able to enable/disable it). Maybe a set of generic views.

If the implementation requires too much dependencies (restframework or things like that), wonder about packaging this feature as a standalone project: when developers just want the "client" features of django-ticketoffice, do they want to download a bunch of server-related dependencies?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.