|
|
@ -24,7 +24,7 @@ from django_etebase.models import UserInfo
|
|
|
|
from django_etebase.signals import user_signed_up
|
|
|
|
from django_etebase.signals import user_signed_up
|
|
|
|
from django_etebase.token_auth.models import AuthToken
|
|
|
|
from django_etebase.token_auth.models import AuthToken
|
|
|
|
from django_etebase.token_auth.models import get_default_expiry
|
|
|
|
from django_etebase.token_auth.models import get_default_expiry
|
|
|
|
from django_etebase.utils import create_user
|
|
|
|
from django_etebase.utils import create_user, get_user_queryset, CallbackContext
|
|
|
|
from django_etebase.views import msgpack_encode, msgpack_decode
|
|
|
|
from django_etebase.views import msgpack_encode, msgpack_decode
|
|
|
|
from .exceptions import AuthenticationFailed, transform_validation_error, ValidationError
|
|
|
|
from .exceptions import AuthenticationFailed, transform_validation_error, ValidationError
|
|
|
|
from .msgpack import MsgpackResponse, MsgpackRoute
|
|
|
|
from .msgpack import MsgpackResponse, MsgpackRoute
|
|
|
@ -268,20 +268,21 @@ async def change_password(data: ChangePassword, request: Request, user: User = D
|
|
|
|
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def signup_save(data: SignupIn) -> User:
|
|
|
|
def signup_save(data: SignupIn, request: Request) -> User:
|
|
|
|
user_data = data.user
|
|
|
|
user_data = data.user
|
|
|
|
with transaction.atomic():
|
|
|
|
with transaction.atomic():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# XXX-TOM
|
|
|
|
user_queryset = get_user_queryset(User.objects.all(), CallbackContext(request.path_params))
|
|
|
|
# view = self.context.get("view", None)
|
|
|
|
|
|
|
|
# user_queryset = get_user_queryset(User.objects.all(), view)
|
|
|
|
|
|
|
|
user_queryset = User.objects.all()
|
|
|
|
|
|
|
|
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data.username.lower()})
|
|
|
|
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data.username.lower()})
|
|
|
|
except User.DoesNotExist:
|
|
|
|
except User.DoesNotExist:
|
|
|
|
# Create the user and save the casing the user chose as the first name
|
|
|
|
# Create the user and save the casing the user chose as the first name
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# XXX-TOM
|
|
|
|
instance = create_user(
|
|
|
|
instance = create_user(**user_data.dict(), password=None, first_name=user_data.username, view=None)
|
|
|
|
**user_data.dict(),
|
|
|
|
|
|
|
|
password=None,
|
|
|
|
|
|
|
|
first_name=user_data.username,
|
|
|
|
|
|
|
|
context=CallbackContext(request.path_params),
|
|
|
|
|
|
|
|
)
|
|
|
|
instance.full_clean()
|
|
|
|
instance.full_clean()
|
|
|
|
except EtebaseValidationError as e:
|
|
|
|
except EtebaseValidationError as e:
|
|
|
|
raise e
|
|
|
|
raise e
|
|
|
@ -298,8 +299,8 @@ def signup_save(data: SignupIn) -> User:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@authentication_router.post("/signup/")
|
|
|
|
@authentication_router.post("/signup/")
|
|
|
|
async def signup(data: SignupIn):
|
|
|
|
async def signup(data: SignupIn, request: Request):
|
|
|
|
user = await sync_to_async(signup_save)(data)
|
|
|
|
user = await sync_to_async(signup_save)(data, request)
|
|
|
|
# XXX-TOM
|
|
|
|
# XXX-TOM
|
|
|
|
data = await sync_to_async(LoginOut.from_orm)(user)
|
|
|
|
data = await sync_to_async(LoginOut.from_orm)(user)
|
|
|
|
await sync_to_async(user_signed_up.send)(sender=user.__class__, request=None, user=user)
|
|
|
|
await sync_to_async(user_signed_up.send)(sender=user.__class__, request=None, user=user)
|
|
|
|