(self, request, format=None)
| 451 | ) |
| 452 | class DemoRegisterView(LoginViewMixin, APIView): |
| 453 | def post(self, request, format=None): |
| 454 | start = time.time() |
| 455 | serializer = DemoRegistrationSerializer( |
| 456 | data=request.data, |
| 457 | ) |
| 458 | serializer.is_valid(raise_exception=True) |
| 459 | reg_dict = serializer.validated_data["register"] |
| 460 | username = reg_dict["username"] |
| 461 | email = reg_dict["email"] |
| 462 | password = reg_dict["password"] |
| 463 | organization_name = "demo_" + username # different |
| 464 | |
| 465 | existing_user_num = User.objects.filter(username=username).count() |
| 466 | if existing_user_num > 0: |
| 467 | raise DuplicateUser("User with username already exists") |
| 468 | existing_user_num = User.objects.filter(email=email).count() |
| 469 | if existing_user_num > 0: |
| 470 | raise DuplicateUser("User with email already exists") |
| 471 | |
| 472 | user = setup_demo4( |
| 473 | organization_name, |
| 474 | username, |
| 475 | email, |
| 476 | password, |
| 477 | org_type=Organization.OrganizationType.EXTERNAL_DEMO, |
| 478 | ) |
| 479 | logger.info("setup_demo4 took %s seconds", time.time() - start) |
| 480 | logger.info(f"Demo user {user} created") |
| 481 | user.organization.organization_type = ( |
| 482 | Organization.OrganizationType.EXTERNAL_DEMO |
| 483 | ) |
| 484 | user.organization.save() |
| 485 | |
| 486 | posthog.capture( |
| 487 | username, |
| 488 | event="demo_register", |
| 489 | properties={"organization": user.organization.organization_name}, |
| 490 | ) |
| 491 | _, token = AuthToken.objects.create(user) |
| 492 | user_data = UserSerializer(user).data |
| 493 | logger.info( |
| 494 | f"Token {token} created for user {user_data}, with org {user.organization}" |
| 495 | ) |
| 496 | return Response( |
| 497 | { |
| 498 | "detail": "Successfully registered.", |
| 499 | "token": token, |
| 500 | "user": user_data, |
| 501 | }, |
| 502 | status=status.HTTP_201_CREATED, |
| 503 | ) |
nothing calls this directly
no test coverage detected