mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Refs #96 -- Completely removed local users
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
from django import forms
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth.forms import \
|
||||
AuthenticationForm as BaseAuthenticationForm
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from pretix.base.models import User
|
||||
|
||||
|
||||
class AuthenticationForm(BaseAuthenticationForm):
|
||||
"""
|
||||
The login form, providing an email and password field. The form already implements
|
||||
validation for correct user data.
|
||||
"""
|
||||
email = forms.EmailField(label=_("Email address"), max_length=254)
|
||||
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||
username = None
|
||||
|
||||
error_messages = {
|
||||
'invalid_login': _("Please enter a correct e-mail address and password."),
|
||||
'inactive': _("This account is inactive.")
|
||||
}
|
||||
|
||||
def __init__(self, request=None, *args, **kwargs):
|
||||
self.request = request
|
||||
self.user_cache = None
|
||||
super(forms.Form, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
password = self.cleaned_data.get('password')
|
||||
|
||||
if email and password:
|
||||
self.user_cache = authenticate(identifier=email.lower(),
|
||||
password=password)
|
||||
if self.user_cache is None:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['invalid_login'],
|
||||
code='invalid_login'
|
||||
)
|
||||
else:
|
||||
self.confirm_login_allowed(self.user_cache)
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class GlobalRegistrationForm(forms.Form):
|
||||
error_messages = {
|
||||
'duplicate_email': _("You already registered with that e-mail address, please use the login form."),
|
||||
'pw_mismatch': _("Please enter the same password twice")
|
||||
}
|
||||
email = forms.EmailField(
|
||||
label=_('Email address'),
|
||||
required=True
|
||||
)
|
||||
password = forms.CharField(
|
||||
label=_('Password'),
|
||||
widget=forms.PasswordInput,
|
||||
required=True
|
||||
)
|
||||
password_repeat = forms.CharField(
|
||||
label=_('Repeat password'),
|
||||
widget=forms.PasswordInput
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
password1 = self.cleaned_data.get('password')
|
||||
password2 = self.cleaned_data.get('password_repeat')
|
||||
|
||||
if password1 and password1 != password2:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['pw_mismatch'],
|
||||
code='pw_mismatch',
|
||||
)
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data['email']
|
||||
if User.objects.filter(identifier=email).exists():
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['duplicate_email'],
|
||||
code='duplicate_email',
|
||||
)
|
||||
return email
|
||||
@@ -4,10 +4,8 @@ from django.contrib.auth import (
|
||||
)
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from pretix.base.forms.auth import LoginForm, RegistrationForm
|
||||
from pretix.base.models import User
|
||||
from pretix.control.forms.auth import (
|
||||
AuthenticationForm, GlobalRegistrationForm,
|
||||
)
|
||||
|
||||
|
||||
def login(request):
|
||||
@@ -21,14 +19,14 @@ def login(request):
|
||||
return redirect(request.GET.get("next", 'control:index'))
|
||||
return redirect('control:index')
|
||||
if request.method == 'POST':
|
||||
form = AuthenticationForm(data=request.POST)
|
||||
form = LoginForm(data=request.POST)
|
||||
if form.is_valid() and form.user_cache:
|
||||
auth_login(request, form.user_cache)
|
||||
if "next" in request.GET:
|
||||
return redirect(request.GET.get("next", 'control:index'))
|
||||
return redirect('control:index')
|
||||
else:
|
||||
form = AuthenticationForm()
|
||||
form = LoginForm()
|
||||
ctx['form'] = form
|
||||
return render(request, 'pretixcontrol/auth/login.html', ctx)
|
||||
|
||||
@@ -51,17 +49,17 @@ def register(request):
|
||||
return redirect(request.GET.get("next", 'control:index'))
|
||||
return redirect('control:index')
|
||||
if request.method == 'POST':
|
||||
form = GlobalRegistrationForm(data=request.POST)
|
||||
form = RegistrationForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
user = User.objects.create_global_user(
|
||||
user = User.objects.create_user(
|
||||
form.cleaned_data['email'], form.cleaned_data['password'],
|
||||
locale=request.LANGUAGE_CODE,
|
||||
timezone=request.timezone if hasattr(request, 'timezone') else settings.TIME_ZONE
|
||||
)
|
||||
user = authenticate(identifier=user.identifier, password=form.cleaned_data['password'])
|
||||
user = authenticate(email=user.email, password=form.cleaned_data['password'])
|
||||
auth_login(request, user)
|
||||
return redirect('control:index')
|
||||
else:
|
||||
form = GlobalRegistrationForm()
|
||||
form = RegistrationForm()
|
||||
ctx['form'] = form
|
||||
return render(request, 'pretixcontrol/auth/register.html', ctx)
|
||||
|
||||
@@ -314,7 +314,7 @@ class EventPermissions(EventPermissionRequiredMixin, TemplateView):
|
||||
if self.formset.is_valid() and self.add_form.is_valid():
|
||||
if self.add_form.has_changed():
|
||||
try:
|
||||
self.add_form.instance.user = User.objects.get(identifier=self.add_form.cleaned_data['user'])
|
||||
self.add_form.instance.user = User.objects.get(email=self.add_form.cleaned_data['user'])
|
||||
self.add_form.instance.user_id = self.add_form.instance.user.id
|
||||
self.add_form.instance.event = self.request.event
|
||||
self.add_form.instance.event_id = self.request.event.identity
|
||||
|
||||
@@ -39,8 +39,7 @@ class OrderList(EventPermissionRequiredMixin, ListView):
|
||||
if self.request.GET.get("user", "") != "":
|
||||
u = self.request.GET.get("user", "")
|
||||
qs = qs.filter(
|
||||
Q(user__identifier__icontains=u) | Q(user__email__icontains=u)
|
||||
| Q(user__givenname__icontains=u) | Q(user__familyname__icontains=u)
|
||||
Q(user__email__icontains=u) | Q(user__givenname__icontains=u) | Q(user__familyname__icontains=u)
|
||||
)
|
||||
if self.request.GET.get("status", "") != "":
|
||||
s = self.request.GET.get("status", "")
|
||||
|
||||
Reference in New Issue
Block a user