mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-24 10:54:05 +01:00
Merge /users/ API into /accounts/
This commit is contained in:
@@ -88,6 +88,39 @@ class AccountExistsSerializer(serializers.Serializer):
|
||||
exists = serializers.BooleanField()
|
||||
|
||||
|
||||
class AccountPasswordSerializer(serializers.ModelSerializer):
|
||||
|
||||
"""A serializer used to change a user password."""
|
||||
|
||||
new_password = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = core_models.User
|
||||
fields = (
|
||||
"password", "new_password", )
|
||||
|
||||
def validate_password(self, value):
|
||||
"""Check password."""
|
||||
if not self.instance.check_password(value):
|
||||
raise serializers.ValidationError("Password not correct")
|
||||
return value
|
||||
|
||||
def validate_new_password(self, value):
|
||||
"""Check new password."""
|
||||
try:
|
||||
validators.validate_length(value)
|
||||
validators.complexity(value)
|
||||
except ValidationError as exc:
|
||||
raise serializers.ValidationError(exc.messages[0])
|
||||
return value
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""Set new password."""
|
||||
instance.set_password(validated_data["new_password"])
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class WritableAccountSerializer(AccountSerializer):
|
||||
"""Serializer to create account."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user