Jonas Havelka
3 years ago
19 changed files with 128 additions and 120 deletions
@ -0,0 +1,27 @@ |
|||
# Nefunkční alternativa vestavěného Usera, který má jméno a mail v přidružené Osobě |
|||
# from django.contrib.auth.models import User as Django_User |
|||
# |
|||
# class Uzivatel(Django_User): |
|||
# class Meta: |
|||
# proxy = True |
|||
# |
|||
# @property |
|||
# def first_name(self): |
|||
# osoby = Osoba.objects.filter(user=self) |
|||
# if len(osoby) == 0: |
|||
# return None |
|||
# return osoby.first().krestni_jmeno |
|||
# |
|||
# @property |
|||
# def last_name(self): |
|||
# osoby = Osoba.objects.filter(user=self) |
|||
# if len(osoby) == 0: |
|||
# return None |
|||
# return osoby.first().prijmeni |
|||
# |
|||
# @property |
|||
# def email(self): |
|||
# osoby = Osoba.objects.filter(user=self) |
|||
# if len(osoby) == 0: |
|||
# return None |
|||
# return osoby.first().email |
@ -0,0 +1,15 @@ |
|||
from django.urls import path |
|||
from . import views |
|||
from django.views.generic.base import RedirectView |
|||
|
|||
urlpatterns = [ |
|||
path('prihlasit/', views.LoginView.as_view(), name='login'), |
|||
path('login/', RedirectView.as_view(pattern_name='login', permanent=True, query_string=True)), |
|||
path('odhlasit/', views.LogoutView.as_view(), name='logout'), |
|||
path('logout/', RedirectView.as_view(pattern_name='logout', permanent=True, query_string=True)), |
|||
path('reset-hesla/', views.PasswordResetView.as_view(), name='reset_password'), |
|||
path('zmena-hesla/', views.PasswordChangeView.as_view(), name='change_password'), |
|||
path('reset-hesla/2/', views.PasswordResetDoneView.as_view(), name='reset_password_done'), |
|||
path('reset-hesla/potvrzeni/<uidb64>/<token>/', views.PasswordResetConfirmView.as_view(), name='reset_password_confirm'), |
|||
path('reset-hesla/hotovo/', views.PasswordResetCompleteView.as_view(), name='reset_password_complete'), |
|||
] |
@ -0,0 +1,31 @@ |
|||
from django.contrib.auth.tokens import PasswordResetTokenGenerator |
|||
from django.contrib.sites.shortcuts import get_current_site |
|||
from django.urls import reverse_lazy |
|||
from django.utils.encoding import force_bytes |
|||
from django.utils.http import urlsafe_base64_encode |
|||
|
|||
|
|||
def posli_reset_hesla(u, request=None): |
|||
uid = urlsafe_base64_encode(force_bytes(u.pk)) |
|||
token = PasswordResetTokenGenerator().make_token(u) |
|||
url = "https://%s%s" % ( |
|||
str(get_current_site(request)), |
|||
str(reverse_lazy("reset_password_confirm", args=[uid, token])) |
|||
) |
|||
|
|||
u.email_user( |
|||
subject="Vítej mezi řešiteli M&M!", |
|||
message="""Milý řešiteli, milá řešitelko, |
|||
|
|||
tvůj e-mail byl právě zaregistrován na mam.matfyz.cz. Heslo si prosím nastav na: %s |
|||
|
|||
Těšíme se na tvé příspěvky do našeho semináře, |
|||
Organizátoři M&M |
|||
|
|||
-- |
|||
|
|||
Tento e-mail byl vygenerován automaticky, chceš-li nás kontaktovat, napiš nám na adresu mam@matfyz.cz. |
|||
""" % url, |
|||
# TODO: templates/autentizace a django/contrib/auth/forms.py říkají, jak na to lépe |
|||
from_email="registrace@mam.mff.cuni.cz", # FIXME: Chceme to mít radši tady, nebo v nastavení? |
|||
) |
@ -0,0 +1,45 @@ |
|||
from django.urls import reverse_lazy |
|||
from django.contrib.auth import views as auth_views |
|||
|
|||
|
|||
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' |
|||
|
|||
|
|||
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') |
Loading…
Reference in new issue