Try to fix change pw
This commit is contained in:
parent
604f7af5ff
commit
62d7b9fe8a
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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')),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user