django2.2: rewrite login and password stack because of removed API

This commit is contained in:
Antoine Bartuccio 2019-10-06 03:02:17 +02:00
parent a177fa8232
commit 59185ab2a8
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 55 additions and 50 deletions

View File

@ -39,23 +39,37 @@ urlpatterns = [
# Login and co # Login and co
re_path(r"^login/$", SithLoginView.as_view(), name="login"), re_path(r"^login/$", SithLoginView.as_view(), name="login"),
re_path(r"^logout/$", logout, name="logout"), re_path(r"^logout/$", logout, name="logout"),
re_path(r"^password_change/$", password_change, name="password_change"), re_path(
r"^password_change/$", SithPasswordChangeView.as_view(), name="password_change"
),
re_path( re_path(
r"^password_change/(?P<user_id>[0-9]+)$", r"^password_change/(?P<user_id>[0-9]+)$",
password_root_change, password_root_change,
name="password_root_change", name="password_root_change",
), ),
re_path( re_path(
r"^password_change/done$", password_change_done, name="password_change_done" r"^password_change/done$",
SithPasswordChangeDoneView.as_view(),
name="password_change_done",
),
re_path(
r"^password_reset/$", SithPasswordResetView.as_view(), name="password_reset"
),
re_path(
r"^password_reset/done$",
SithPasswordResetDoneView.as_view(),
name="password_reset_done",
), ),
re_path(r"^password_reset/$", password_reset, name="password_reset"),
re_path(r"^password_reset/done$", password_reset_done, name="password_reset_done"),
re_path( re_path(
r"^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$", r"^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$",
password_reset_confirm, SithPasswordResetConfirmView.as_view(),
name="password_reset_confirm", name="password_reset_confirm",
), ),
re_path(r"^reset/done/$", password_reset_complete, name="password_reset_complete"), re_path(
r"^reset/done/$",
SithPasswordResetCompleteView.as_view(),
name="password_reset_complete",
),
re_path(r"^register$", register, name="register"), re_path(r"^register$", register, name="register"),
# Group handling # Group handling
re_path(r"^group/$", GroupListView.as_view(), name="group_list"), re_path(r"^group/$", GroupListView.as_view(), name="group_list"),

View File

@ -26,6 +26,7 @@
# This file contains all the views that concern the user model # This file contains all the views that concern the user model
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth import views from django.contrib.auth import views
from django.contrib.auth.forms import PasswordChangeForm
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.urls import reverse from django.urls import reverse
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
@ -76,6 +77,24 @@ class SithLoginView(views.LoginView):
template_name = "core/login.jinja" template_name = "core/login.jinja"
authentication_form = LoginForm authentication_form = LoginForm
form_class = PasswordChangeForm
class SithPasswordChangeView(views.PasswordChangeView):
"""
Allows a user to change its password
"""
template_name = "core/password_change.jinja"
success_url = reverse_lazy("core:password_change_done")
class SithPasswordChangeDoneView(views.PasswordChangeDoneView):
"""
Allows a user to change its password
"""
template_name = "core/password_change_done.jinja"
def logout(request): def logout(request):
@ -85,26 +104,6 @@ def logout(request):
return views.logout_then_login(request) return views.logout_then_login(request)
def password_change(request):
"""
Allows a user to change its password
"""
return views.password_change(
request,
template_name="core/password_change.jinja",
post_change_redirect=reverse("core:password_change_done"),
)
def password_change_done(request):
"""
Allows a user to change its password
"""
return views.password_change_done(
request, template_name="core/password_change_done.jinja"
)
def password_root_change(request, user_id): def password_root_change(request, user_id):
""" """
Allows a root user to change someone's password Allows a root user to change someone's password
@ -126,47 +125,39 @@ def password_root_change(request, user_id):
) )
def password_reset(request): class SithPasswordResetView(views.PasswordResetView):
""" """
Allows someone to enter an email adresse for resetting password Allows someone to enter an email adresse for resetting password
""" """
return views.password_reset(
request, template_name = "core/password_reset.jinja"
template_name="core/password_reset.jinja", email_template_name = "core/password_reset_email.jinja"
email_template_name="core/password_reset_email.jinja", success_url = reverse_lazy("core:password_reset_done")
post_reset_redirect="core:password_reset_done",
)
def password_reset_done(request): class SithPasswordResetDoneView(views.PasswordResetDoneView):
""" """
Confirm that the reset email has been sent Confirm that the reset email has been sent
""" """
return views.password_reset_done(
request, template_name="core/password_reset_done.jinja" template_name = "core/password_reset_done.jinja"
)
def password_reset_confirm(request, uidb64=None, token=None): class SithPasswordResetConfirmView(views.PasswordResetConfirmView):
""" """
Provide a reset password formular Provide a reset password form
""" """
return views.password_reset_confirm(
request, template_name = "core/password_reset_confirm.jinja"
uidb64=uidb64, success_url = reverse_lazy("core:password_reset_complete")
token=token,
post_reset_redirect="core:password_reset_complete",
template_name="core/password_reset_confirm.jinja",
)
def password_reset_complete(request): class SithPasswordResetCompleteView(views.PasswordResetCompleteView):
""" """
Confirm the password has sucessfully been reset Confirm the password has sucessfully been reset
""" """
return views.password_reset_complete(
request, template_name="core/password_reset_complete.jinja" template_name = "core/password_reset_complete.jinja"
)
def register(request): def register(request):