|
|
|
from django.conf import settings
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.contrib.auth import views as auth_views
|
|
|
|
|
|
|
|
from django.contrib.auth import login as auth_login
|
|
|
|
|
|
|
|
from various.autentizace.forms import LoginForm
|
|
|
|
|
|
|
|
|
|
|
|
class LoginView(auth_views.LoginView):
|
|
|
|
# Jen vezmeme vestavěný a dáme mu vhodný template a přesměrovací URL
|
|
|
|
template_name = 'autentizace/login.html'
|
|
|
|
authentication_form = LoginForm
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
""" Okopírováno z django/contrib/auth/views.py s přidáním nekonečného přihlášení """
|
|
|
|
auth_login(self.request, form.get_user())
|
|
|
|
if form.cleaned_data["disable_logout"]:
|
|
|
|
form.request.session.set_expiry(settings.DOBA_ODHLASENI_PRI_ZASKRTNUTI_NEODHLASOVAT)
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
|
|
|
|
class LogoutView(auth_views.LogoutView):
|
|
|
|
# Jen vezmeme vestavěný a dáme mu vhodný template a přesměrovací URL
|
|
|
|
template_name = 'autentizace/logout.html'
|
|
|
|
# Pavel: Vůbec nevím, proč to s _lazy funguje, ale bez toho to bylo rozbité.
|
|
|
|
next_page = reverse_lazy('titulni_strana')
|
|
|
|
|
|
|
|
|
|
|
|
# Nejsem si jistý, který view co dostává, tak zahazuji všechny POSTy
|
|
|
|
class PasswordResetView(auth_views.PasswordResetView):
|
|
|
|
""" Chci resetovat heslo. """
|
|
|
|
template_name = 'autentizace/reset_hesla.html'
|
|
|
|
success_url = reverse_lazy('reset_password_done')
|
|
|
|
from_email = 'login@mam.mff.cuni.cz'
|
|
|
|
email_template_name = 'autentizace/password_reset_email.html'
|
|
|
|
subject_template_name = 'autentizace/password_reset_subject.txt'
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetDoneView(auth_views.PasswordResetDoneView):
|
|
|
|
""" Poslali jsme e-mail (pokud bylo kam)). """
|
|
|
|
template_name = 'autentizace/reset_poslan.html'
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):
|
|
|
|
""" Vymysli si heslo. """
|
|
|
|
template_name = 'autentizace/nove_heslo.html'
|
|
|
|
success_url = reverse_lazy('reset_password_complete')
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetCompleteView(auth_views.PasswordResetCompleteView):
|
|
|
|
""" Heslo se asi změnilo."""
|
|
|
|
template_name = 'autentizace/nove_nastaveno.html'
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordChangeView(auth_views.PasswordChangeView):
|
|
|
|
# template_name = 'seminar/password_change.html'
|
|
|
|
success_url = reverse_lazy('titulni_strana')
|