mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-29 11:44:28 +01:00
Account creation form improvements.
This commit is contained in:
@@ -305,7 +305,13 @@ class WritableAccountSerializer(AccountSerializer):
|
||||
raise serializers.ValidationError({
|
||||
"username": _("Must be equal to mailbox full_address")
|
||||
})
|
||||
if not self.partial and not data.get("random_password"):
|
||||
condition = (
|
||||
not data.get("random_password") and (
|
||||
data.get("password") or
|
||||
not self.partial
|
||||
)
|
||||
)
|
||||
if condition:
|
||||
password = data.get("password")
|
||||
if password:
|
||||
try:
|
||||
|
||||
@@ -160,9 +160,11 @@ class WritableAccountSerializer(v1_serializers.WritableAccountSerializer):
|
||||
)
|
||||
|
||||
class Meta(v1_serializers.WritableAccountSerializer.Meta):
|
||||
fields = v1_serializers.WritableAccountSerializer.Meta.fields + (
|
||||
"aliases",
|
||||
)
|
||||
fields = tuple(
|
||||
field
|
||||
for field in v1_serializers.WritableAccountSerializer.Meta.fields
|
||||
if field != "random_password"
|
||||
) + ("aliases", )
|
||||
|
||||
def validate_aliases(self, value):
|
||||
"""Check if required domains are locals and user can access them."""
|
||||
|
||||
@@ -161,6 +161,12 @@ class AccountViewSet(v1_viewsets.AccountViewSet):
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return response.Response(status=204)
|
||||
|
||||
@action(methods=["get"], detail=False)
|
||||
def random_password(self, request, **kwargs):
|
||||
"""Generate a random password."""
|
||||
password = lib.make_password()
|
||||
return response.Response({"password": password})
|
||||
|
||||
|
||||
class IdentityViewSet(viewsets.ViewSet):
|
||||
"""Viewset for identities."""
|
||||
|
||||
Reference in New Issue
Block a user