2021-03-21 15:50:50 +00:00
|
|
|
from django.contrib.auth.views import LoginView as Login, LogoutView as Logout
|
|
|
|
from django.http.response import HttpResponseRedirect
|
|
|
|
from django.contrib.auth import login
|
2021-03-22 17:42:07 +00:00
|
|
|
from django.shortcuts import resolve_url
|
|
|
|
from django.conf import settings
|
2021-03-23 18:23:04 +00:00
|
|
|
from django.views.generic import FormView
|
|
|
|
from django.contrib import messages
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-03-23 18:23:04 +00:00
|
|
|
from .forms import RegistrationForm, VerificationForm
|
2021-03-21 15:50:50 +00:00
|
|
|
from .models import User
|
2021-03-23 18:23:04 +00:00
|
|
|
from .mixins import SuperUserRequiredMixin
|
|
|
|
|
|
|
|
from clients.models import ClientProfile
|
|
|
|
from partners.models import PartnerProfile
|
2021-05-30 05:45:07 +00:00
|
|
|
from mail.views import MailView
|
2021-03-21 15:50:50 +00:00
|
|
|
|
|
|
|
class LoginView(Login):
|
2021-04-08 09:30:19 +00:00
|
|
|
template_name = "localauth/login.html"
|
2021-03-21 15:50:50 +00:00
|
|
|
|
|
|
|
class LogoutView(Logout):
|
|
|
|
next_page = "/"
|
|
|
|
|
|
|
|
class RegistrationView(Login):
|
|
|
|
form_class = RegistrationForm
|
|
|
|
template_name = "localauth/register.html"
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
2021-03-23 18:23:04 +00:00
|
|
|
user = User.objects.create_user(form.cleaned_data["email"])
|
|
|
|
user.set_password(form.cleaned_data["password1"])
|
2021-04-14 11:15:36 +00:00
|
|
|
user.save()
|
|
|
|
|
2021-03-21 15:50:50 +00:00
|
|
|
login(self.request, user)
|
2021-03-23 18:23:04 +00:00
|
|
|
|
|
|
|
messages.success(self.request, "Erfolgreich registriert!")
|
2021-03-21 15:50:50 +00:00
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
def get_default_redirect_url(self):
|
2021-03-23 18:23:04 +00:00
|
|
|
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)
|
|
|
|
|
2021-05-30 05:45:07 +00:00
|
|
|
return HttpResponseRedirect(resolve_url("localauth:verify"))
|
|
|
|
|
|
|
|
class EmailVerificationHTMLMailView(MailView):
|
|
|
|
template_name = "localauth/mail/verify.html"
|
|
|
|
|