Refs #775 -- Pluggable authentication backends (#1447)

* Drag-and-drop: Force csrf_token to be present

* Rough design

* Missing file

* b.visble

* Forms

* Docs

* Tests

* Fix variable
This commit is contained in:
Raphael Michel
2019-10-17 09:11:03 +02:00
committed by GitHub
parent e34511b984
commit 8a6a515b6a
25 changed files with 476 additions and 72 deletions

View File

@@ -0,0 +1,38 @@
from collections import OrderedDict
from django import forms
from pretix.base.auth import BaseAuthBackend
from pretix.base.models import User
class TestFormAuthBackend(BaseAuthBackend):
identifier = 'test_form'
verbose_name = 'Form'
@property
def login_form_fields(self) -> dict:
return OrderedDict([
('username', forms.CharField(max_length=100)),
('password', forms.CharField(max_length=100)),
])
def form_authenticate(self, request, form_data):
if form_data['username'] == 'foo' and form_data['password'] == 'bar':
return User.objects.get_or_create(
email='foo@example.com',
auth_backend='test_form'
)[0]
class TestRequestAuthBackend(BaseAuthBackend):
identifier = 'test_request'
verbose_name = 'Request'
visible = False
def request_authenticate(self, request):
if 'X-Login-Email' in request.headers:
return User.objects.get_or_create(
email=request.headers['X-Login-Email'],
auth_backend='test_request'
)[0]