mirror of
https://github.com/etesync/server
synced 2024-11-14 04:49:18 +00:00
Add support for a custom user creation function.
This commit is contained in:
parent
e41f8455f2
commit
c9463cadba
@ -54,6 +54,13 @@ class AppSettings:
|
||||
return self.import_from_str(get_user_queryset)
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def CREATE_USER_FUNC(self): # pylint: disable=invalid-name
|
||||
func = self._setting("CREATE_USER_FUNC", None)
|
||||
if func is not None:
|
||||
return self.import_from_str(func)
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name
|
||||
return self._setting("CHALLENGE_VALID_SECONDS", 60)
|
||||
|
@ -20,7 +20,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
from rest_framework import serializers
|
||||
from . import models
|
||||
from .utils import get_user_queryset
|
||||
from .utils import get_user_queryset, create_user
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@ -399,7 +399,10 @@ class AuthenticationSignupSerializer(serializers.Serializer):
|
||||
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data['username'].lower()})
|
||||
except User.DoesNotExist:
|
||||
# Create the user and save the casing the user chose as the first name
|
||||
instance = User.objects.create_user(**user_data, password=None, first_name=user_data['username'])
|
||||
try:
|
||||
instance = create_user(**user_data, password=None, first_name=user_data['username'], view=view)
|
||||
except Exception as e:
|
||||
raise serializers.ValidationError(e)
|
||||
|
||||
if hasattr(instance, 'userinfo'):
|
||||
raise serializers.ValidationError('User already exists')
|
||||
|
@ -10,3 +10,11 @@ def get_user_queryset(queryset, view):
|
||||
if custom_func is not None:
|
||||
return custom_func(queryset, view)
|
||||
return queryset
|
||||
|
||||
|
||||
def create_user(*args, **kwargs):
|
||||
custom_func = app_settings.CREATE_USER_FUNC
|
||||
if custom_func is not None:
|
||||
return custom_func(*args, **kwargs)
|
||||
_ = kwargs.pop('view')
|
||||
return User.objects.create_user(*args, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user