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():
|
if account_models.User.objects.filter(username__iexact=value).exists():
|
||||||
raise serializers.ValidationError()
|
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
|
return value
|
||||||
|
|
||||||
def validate_email(self, value):
|
def validate_email(self, value):
|
||||||
|
|
@ -67,6 +62,13 @@ class SignupSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
"""Overridden create method"""
|
"""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(
|
obj = account_models.User.objects.make(
|
||||||
username=validated_data.get('username'),
|
username=validated_data.get('username'),
|
||||||
password=validated_data.get('password'),
|
password=validated_data.get('password'),
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,8 @@ import logging
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
from io import BytesIO
|
|
||||||
from PIL import Image
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from django.conf import settings
|
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.contrib.gis.geos import Point
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.utils.timezone import datetime
|
from django.utils.timezone import datetime
|
||||||
|
from PIL import Image
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
|
|
||||||
|
|
@ -57,9 +57,14 @@ def username_validator(username: str) -> bool:
|
||||||
|
|
||||||
def username_random():
|
def username_random():
|
||||||
"""Generate random username"""
|
"""Generate random username"""
|
||||||
return '{letters}{digits}'.format(
|
username = list('{letters}{digits}'.format(
|
||||||
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(5)]),
|
letters=''.join([random.choice(string.ascii_lowercase) for _ in range(4)]),
|
||||||
digits=random.randrange(100, 1000)
|
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