Implement django password reset
This commit is contained in:
parent
36c329f7a7
commit
a183eb2bbd
@ -52,10 +52,12 @@ urlpatterns = [
|
|||||||
name='user-delete-confirm'),
|
name='user-delete-confirm'),
|
||||||
path('user/<str:user_dn>/delete/realm/<int:realm_id>/', account_manager.views.user_views.user_delete,
|
path('user/<str:user_dn>/delete/realm/<int:realm_id>/', account_manager.views.user_views.user_delete,
|
||||||
name='user-delete'),
|
name='user-delete'),
|
||||||
path('reset/<uidb64>/<token>/', account_manager.views.user_views.LdapPasswordResetConfirmView.as_view(),
|
path('accounts/reset/<uidb64>/<token>/', account_manager.views.user_views.LdapPasswordResetConfirmView.as_view(),
|
||||||
name='ldap_password_reset_confirm'),
|
name='ldap_password_reset_confirm'),
|
||||||
|
path('accounts/password_change/', account_manager.views.user_views.LdapPasswordChangeView.as_view(),
|
||||||
|
name='password_change'),
|
||||||
|
|
||||||
# Extra
|
# Extra
|
||||||
path('permission-denied/', main_views.permission_denied, name='permission-denied'),
|
path('permission-denied/', main_views.permission_denied, name='permission-denied'),
|
||||||
path('account/deleted/<int:realm_id>/', account_manager.views.user_views.user_deleted, name='account-deleted'),
|
path('accounts/deleted/<int:realm_id>/', account_manager.views.user_views.user_deleted, name='account-deleted'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.views import PasswordResetConfirmView
|
from django.contrib.auth.views import PasswordResetConfirmView, PasswordChangeView
|
||||||
from django.contrib.sites.shortcuts import get_current_site
|
from django.contrib.sites.shortcuts import get_current_site
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
@ -269,5 +269,15 @@ class LdapPasswordResetConfirmView(PasswordResetConfirmView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
user = form.save()
|
user = form.save()
|
||||||
password = form.cleaned_data['new_password1']
|
password = form.cleaned_data['new_password1']
|
||||||
|
LdapUser.base_dn = LdapUser.ROOT_DN
|
||||||
|
LdapUser.password_reset(user, password)
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
class LdapPasswordChangeView(PasswordChangeView):
|
||||||
|
def form_valid(self, form):
|
||||||
|
user = form.save()
|
||||||
|
password = form.cleaned_data['new_password1']
|
||||||
|
LdapUser.base_dn = LdapUser.ROOT_DN
|
||||||
LdapUser.password_reset(user, password)
|
LdapUser.password_reset(user, password)
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
@ -15,9 +15,14 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
from django.contrib.auth import views as auth_views
|
||||||
|
from django.contrib.auth.decorators import user_passes_test
|
||||||
|
|
||||||
|
login_forbidden = user_passes_test(lambda u: u.is_anonymous(), '/')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('account_manager.urls')),
|
path('', include('account_manager.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('accounts/login/', auth_views.LoginView.as_view(), {'redirect_if_logged_in': '/'}, name='login'),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
]
|
]
|
||||||
|
|||||||
16
templates/registration/password_change_done.html
Normal file
16
templates/registration/password_change_done.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends 'base.jinja2' %}
|
||||||
|
{% import 'macros/form_macros.jinja2' as mform %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="col-12 ">
|
||||||
|
<div class="row justify-content-center justify-content-sm-center">
|
||||||
|
<div class="col-12 col-sm-8 col-md-7 col-lg-5 col-xl-4 bg-white text-dark p-3 mt-5">
|
||||||
|
<h1 class="mb-4">Passwort geändert</h1>
|
||||||
|
<p>Dein Passwort wurde erfolgreich geändert</p>
|
||||||
|
|
||||||
|
<a href="{{ url('realm-home')}}"
|
||||||
|
class="btn btn-success p-2 w-100">Zurück zur Profilseite</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user