From 62d7b9fe8a9221e50294d4d18b8d05f867e9f33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20G=C3=B6tz?= Date: Tue, 28 May 2019 23:22:58 +0200 Subject: [PATCH] Try to fix change pw --- src/account_manager/models.py | 2 +- src/account_manager/views/user_views.py | 11 +++++++++-- src/core/urls.py | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/account_manager/models.py b/src/account_manager/models.py index ecadf45..48bb3f6 100644 --- a/src/account_manager/models.py +++ b/src/account_manager/models.py @@ -84,7 +84,7 @@ class LdapUser(Model): LdapUser.base_dn = LdapUser.ROOT_DN ldap_user = LdapUser.objects.get(username=user.username) ldap_user.password = raw_password - LdapUser.base_dn = re.compile('(uid=[a-zA-Z0-9_]*),(.*)').match(ldap_user.dn).group(2) + LdapUser.base_dn = re.compile('(uid=[a-zA-Z0-9_-]*),(.*)').match(ldap_user.dn).group(2) ldap_user.save() @staticmethod diff --git a/src/account_manager/views/user_views.py b/src/account_manager/views/user_views.py index 2533436..a4530aa 100644 --- a/src/account_manager/views/user_views.py +++ b/src/account_manager/views/user_views.py @@ -8,7 +8,7 @@ from django.contrib.auth.views import PasswordResetConfirmView, PasswordChangeVi from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import ObjectDoesNotExist from django.db import IntegrityError -from django.http import HttpRequest +from django.http import HttpRequest, HttpResponseRedirect from django.shortcuts import render, redirect from django.utils.translation import gettext as _ from ldap import ALREADY_EXISTS, OBJECT_CLASS_VIOLATION @@ -498,9 +498,16 @@ class LdapPasswordResetConfirmView(PasswordResetConfirmView): class LdapPasswordChangeView(PasswordChangeView): + def form_valid(self, form): + logger.info('VALIDATED') user = form.save() password = form.cleaned_data['new_password1'] LdapUser.base_dn = LdapUser.ROOT_DN LdapUser.password_reset(user, password) - return super().form_valid(form) + logger.info('VALIDATED') + # return HttpResponseRedirect(self.get_success_url()) + cached_request = super().form_valid(form) + user.set_unusable_password() + user.save() + return cached_request diff --git a/src/core/urls.py b/src/core/urls.py index 3c27ba8..7bbaeb6 100644 --- a/src/core/urls.py +++ b/src/core/urls.py @@ -18,6 +18,7 @@ from django.urls import path, include from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import user_passes_test from account_manager.forms import LdapPasswordResetForm +from account_manager.views.user_views import LdapPasswordChangeView from .views import about login_forbidden = user_passes_test(lambda u: u.is_anonymous(), '/') @@ -31,5 +32,6 @@ urlpatterns = [ auth_views.PasswordResetView.as_view(html_email_template_name='registration/password_reset_email.html', form_class=LdapPasswordResetForm), name='password_reset'), + path('accounts/', include('django.contrib.auth.urls')), ]