Send password to LDAP on password change
This commit is contained in:
parent
6fa73af0be
commit
67c1d480df
|
@ -4,10 +4,11 @@ from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.validators import UniqueValidator
|
from rest_framework.validators import UniqueValidator
|
||||||
from rest_auth.registration.serializers import RegisterSerializer
|
from rest_auth.registration.serializers import RegisterSerializer
|
||||||
|
from rest_auth.serializers import PasswordChangeSerializer
|
||||||
from rest_auth.serializers import UserDetailsSerializer
|
from rest_auth.serializers import UserDetailsSerializer
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from . import models, fields, utils
|
from . import models, fields, utils, utils_ldap
|
||||||
from .. import settings
|
from .. import settings
|
||||||
|
|
||||||
class TransactionSerializer(serializers.ModelSerializer):
|
class TransactionSerializer(serializers.ModelSerializer):
|
||||||
|
@ -347,7 +348,7 @@ class UserSerializer(serializers.ModelSerializer):
|
||||||
return serializer.data
|
return serializer.data
|
||||||
|
|
||||||
|
|
||||||
class RegistrationSerializer(RegisterSerializer):
|
class MyRegisterSerializer(RegisterSerializer):
|
||||||
first_name = serializers.CharField(max_length=32)
|
first_name = serializers.CharField(max_length=32)
|
||||||
last_name = serializers.CharField(max_length=32)
|
last_name = serializers.CharField(max_length=32)
|
||||||
existing_member = serializers.ChoiceField(['true', 'false'])
|
existing_member = serializers.ChoiceField(['true', 'false'])
|
||||||
|
@ -367,3 +368,16 @@ class RegistrationSerializer(RegisterSerializer):
|
||||||
raise ValidationError(dict(non_field_errors='Can only register from Protospace.'))
|
raise ValidationError(dict(non_field_errors='Can only register from Protospace.'))
|
||||||
|
|
||||||
utils.register_user(data, user)
|
utils.register_user(data, user)
|
||||||
|
|
||||||
|
class MyPasswordChangeSerializer(PasswordChangeSerializer):
|
||||||
|
def save(self):
|
||||||
|
data = dict(
|
||||||
|
username=self.user.username,
|
||||||
|
password1=self.request.data['new_password1'],
|
||||||
|
)
|
||||||
|
|
||||||
|
if utils_ldap.is_configured():
|
||||||
|
if utils_ldap.set_password(data) != 200:
|
||||||
|
raise ValidationError(dict(non_field_errors='Problem connecting to LDAP server: set.'))
|
||||||
|
|
||||||
|
super().save()
|
||||||
|
|
|
@ -333,8 +333,9 @@ class StatsView(views.APIView):
|
||||||
|
|
||||||
|
|
||||||
class RegistrationView(RegisterView):
|
class RegistrationView(RegisterView):
|
||||||
serializer_class = serializers.RegistrationSerializer
|
serializer_class = serializers.MyRegisterSerializer
|
||||||
|
|
||||||
|
|
||||||
class PasswordChangeView(PasswordChangeView):
|
class PasswordChangeView(PasswordChangeView):
|
||||||
permission_classes = [AllowMetadata | IsAuthenticated]
|
permission_classes = [AllowMetadata | IsAuthenticated]
|
||||||
|
serializer_class = serializers.MyPasswordChangeSerializer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user