Verified Commit 59185ab2 authored by Sli's avatar Sli
Browse files

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

parent a177fa82
......@@ -39,23 +39,37 @@ urlpatterns = [
# Login and co
re_path(r"^login/$", SithLoginView.as_view(), name="login"),
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(
r"^password_change/(?P<user_id>[0-9]+)$",
password_root_change,
name="password_root_change",
),
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(
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",
),
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"),
# Group handling
re_path(r"^group/$", GroupListView.as_view(), name="group_list"),
......
......@@ -26,6 +26,7 @@
# This file contains all the views that concern the user model
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth import views
from django.contrib.auth.forms import PasswordChangeForm
from django.utils.translation import ugettext as _
from django.urls import reverse
from django.core.exceptions import PermissionDenied, ValidationError
......@@ -76,33 +77,31 @@ class SithLoginView(views.LoginView):
template_name = "core/login.jinja"
authentication_form = LoginForm
form_class = PasswordChangeForm
def logout(request):
class SithPasswordChangeView(views.PasswordChangeView):
"""
The logout view
Allows a user to change its password
"""
return views.logout_then_login(request)
template_name = "core/password_change.jinja"
success_url = reverse_lazy("core:password_change_done")
def password_change(request):
class SithPasswordChangeDoneView(views.PasswordChangeDoneView):
"""
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"),
)
template_name = "core/password_change_done.jinja"
def password_change_done(request):
def logout(request):
"""
Allows a user to change its password
The logout view
"""
return views.password_change_done(
request, template_name="core/password_change_done.jinja"
)
return views.logout_then_login(request)
def password_root_change(request, user_id):
......@@ -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
"""
return views.password_reset(
request,
template_name="core/password_reset.jinja",
email_template_name="core/password_reset_email.jinja",
post_reset_redirect="core:password_reset_done",
)
template_name = "core/password_reset.jinja"
email_template_name = "core/password_reset_email.jinja"
success_url = reverse_lazy("core:password_reset_done")
def password_reset_done(request):
class SithPasswordResetDoneView(views.PasswordResetDoneView):
"""
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,
uidb64=uidb64,
token=token,
post_reset_redirect="core:password_reset_complete",
template_name="core/password_reset_confirm.jinja",
)
template_name = "core/password_reset_confirm.jinja"
success_url = reverse_lazy("core:password_reset_complete")
def password_reset_complete(request):
class SithPasswordResetCompleteView(views.PasswordResetCompleteView):
"""
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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment