Skip to content

Commit

Permalink
validate password if not None when creating user
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Jul 14, 2023
1 parent ac081ca commit 61c9fbc
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions onadata/libs/serializers/user_profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,16 @@ def create(self, validated_data):
_(f"User account {username} already exists")
) from e

try:
validate_password("" if password is None else password, user=new_user)

except ValidationError as e:
# Delete created user object if created
# to allow re-registration
if new_user:
new_user.delete()
raise serializers.ValidationError({"password": e.messages})
if password is not None:
try:
validate_password(password, user=new_user)

except ValidationError as e:
# Delete created user object if created
# to allow re-registration
if new_user:
new_user.delete()
raise serializers.ValidationError({"password": e.messages})

new_user.is_active = True
new_user.first_name = params.get("first_name")
Expand Down

0 comments on commit 61c9fbc

Please sign in to comment.