JourneyJoker/localauth/views.py
Klaus-Uwe Mitterer a3d31c5cc3 Implement PDF generator
Improve mail view
Implement voucher generation
2021-05-31 07:20:27 +02:00

56 lines
No EOL
1.8 KiB
Python

from django.contrib.auth.views import LoginView as Login, LogoutView as Logout
from django.http.response import HttpResponseRedirect
from django.contrib.auth import login
from django.shortcuts import resolve_url
from django.conf import settings
from django.views.generic import FormView
from django.contrib import messages
from .forms import RegistrationForm, VerificationForm
from .models import User
from .mixins import SuperUserRequiredMixin
from clients.models import ClientProfile
from partners.models import PartnerProfile
from mail.views import MailView
class LoginView(Login):
template_name = "localauth/login.html"
class LogoutView(Logout):
next_page = "/"
class RegistrationView(Login):
form_class = RegistrationForm
template_name = "localauth/register.html"
def form_valid(self, form):
user = User.objects.create_user(form.cleaned_data["email"])
user.set_password(form.cleaned_data["password1"])
user.save()
login(self.request, user)
messages.success(self.request, "Erfolgreich registriert!")
return HttpResponseRedirect(self.get_success_url())
def get_default_redirect_url(self):
return resolve_url(self.next_page or settings.REGISTER_REDIRECT_URL)
class VerificationView(SuperUserRequiredMixin, FormView):
form_class = VerificationForm
template_name = "localauth/verify.html"
def form_valid(self, form):
pid = form.cleaned_data["profile"]
ptype = ClientProfile if profile.startswith("C") else PartnerProfile
pobj = ptype.objects.get(id=profile[1:])
pobj.update(verified=True)
messages.success(self.request, "Benutzer %s bestätigt!" % pobj.full_name)
return HttpResponseRedirect(resolve_url("localauth:verify"))
class EmailVerificationMailView(MailView):
template_name = "localauth/mail/verify.html"