Fix for front auth
This commit is contained in:
parent
49673d64af
commit
42190e0e28
|
|
@ -43,11 +43,6 @@ class SignupSerializer(serializers.ModelSerializer):
|
|||
if account_models.User.objects.filter(username__iexact=value).exists():
|
||||
raise serializers.ValidationError()
|
||||
|
||||
else:
|
||||
value = utils_methods.username_random()
|
||||
while account_models.User.objects.filter(username__iexact=value).exists():
|
||||
value = utils_methods.username_random()
|
||||
|
||||
return value
|
||||
|
||||
def validate_email(self, value):
|
||||
|
|
@ -67,6 +62,13 @@ class SignupSerializer(serializers.ModelSerializer):
|
|||
|
||||
def create(self, validated_data):
|
||||
"""Overridden create method"""
|
||||
|
||||
username = validated_data.get('username')
|
||||
if not username:
|
||||
username = utils_methods.username_random()
|
||||
while account_models.User.objects.filter(username__iexact=username).exists():
|
||||
username = utils_methods.username_random()
|
||||
|
||||
obj = account_models.User.objects.make(
|
||||
username=validated_data.get('username'),
|
||||
password=validated_data.get('password'),
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ import logging
|
|||
import random
|
||||
import re
|
||||
import string
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
from collections import namedtuple
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
|
@ -13,6 +12,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.contrib.gis.geos import Point
|
||||
from django.http.request import HttpRequest
|
||||
from django.utils.timezone import datetime
|
||||
from PIL import Image
|
||||
from rest_framework import status
|
||||
from rest_framework.request import Request
|
||||
|
||||
|
|
@ -57,9 +57,14 @@ def username_validator(username: str) -> bool:
|
|||
|
||||
def username_random():
|
||||
"""Generate random username"""
|
||||
return '{letters}{digits}'.format(
|
||||
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(5)]),
|
||||
username = list('{letters}{digits}'.format(
|
||||
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(4)]),
|
||||
digits=random.randrange(100, 1000)
|
||||
))
|
||||
random.shuffle(username)
|
||||
return '{first}{username}'.format(
|
||||
first=random.choice(string.ascii_lowercase),
|
||||
username=''.join(username)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user