mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
* initial commit * API auth * Hierarchical URLs * Add session auth * Strong hierarchy * Add filters * Add i18n fields, questions * More viewsets and serializers * Ticket download * Add OrderPosition serializer * View-level permissions * More tests * More tests * Add basic API docs * Add REST API to docs frontpage * Tests for order endpoints * Add invoice tests * Voucher and waitinglist tests * Doc draft * order docs * Docs on all viewsets * Disable DRF docs, style sphinx, style browsable API * Fix tests * deprecated imports * Test foo * Attendee names * Fix migration problems * Remove browsable API, plugin integration * Doc fixes
22 lines
722 B
Python
22 lines
722 B
Python
from django.contrib.auth.models import AnonymousUser
|
|
from rest_framework import exceptions
|
|
from rest_framework.authentication import TokenAuthentication
|
|
|
|
from pretix.base.models.organizer import TeamAPIToken
|
|
|
|
|
|
class TeamTokenAuthentication(TokenAuthentication):
|
|
model = TeamAPIToken
|
|
|
|
def authenticate_credentials(self, key):
|
|
model = self.get_model()
|
|
try:
|
|
token = model.objects.select_related('team', 'team__organizer').get(token=key)
|
|
except model.DoesNotExist:
|
|
raise exceptions.AuthenticationFailed('Invalid token.')
|
|
|
|
if not token.active:
|
|
raise exceptions.AuthenticationFailed('Token inactive or deleted.')
|
|
|
|
return AnonymousUser(), token
|