mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
* 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:
38
src/tests/testdummy/auth.py
Normal file
38
src/tests/testdummy/auth.py
Normal 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]
|
||||
Reference in New Issue
Block a user