2020-06-11 00:54:34 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2019-03-13 18:26:01 +01:00
|
|
|
from django.conf import settings
|
2020-06-11 00:54:34 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2019-03-13 18:26:01 +01:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
|
|
|
from confirmation.models import Confirmation, create_confirmation_link
|
2019-01-11 20:56:22 +01:00
|
|
|
from zerver.lib.response import json_success
|
2019-03-13 18:26:01 +01:00
|
|
|
from zerver.lib.subdomains import get_subdomain
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import UserProfile
|
2019-03-13 18:26:01 +01:00
|
|
|
from zerver.views.auth import create_preregistration_user
|
|
|
|
from zerver.views.registration import accounts_register
|
|
|
|
|
2019-01-11 20:56:22 +01:00
|
|
|
|
2020-10-23 02:43:28 +02:00
|
|
|
# This is used only by the Puppeteer test in 00-realm-creation.js.
|
2019-01-11 20:56:22 +01:00
|
|
|
def confirmation_key(request: HttpRequest) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
return json_success(request.session.get("confirmation_key"))
|
2019-03-13 18:26:01 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-13 18:26:01 +01:00
|
|
|
def modify_postdata(request: HttpRequest, **kwargs: Any) -> None:
|
|
|
|
request.POST._mutable = True
|
|
|
|
for key, value in kwargs.items():
|
|
|
|
request.POST[key] = value
|
|
|
|
request.POST._mutable = False
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-13 18:26:01 +01:00
|
|
|
@csrf_exempt
|
|
|
|
def register_development_user(request: HttpRequest) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
if get_subdomain(request) == "":
|
|
|
|
request.META["HTTP_HOST"] = settings.REALM_HOSTS["zulip"]
|
2019-03-13 18:26:01 +01:00
|
|
|
count = UserProfile.objects.count()
|
2021-02-12 08:20:45 +01:00
|
|
|
name = f"user-{count}"
|
|
|
|
email = f"{name}@zulip.com"
|
2021-02-12 08:19:30 +01:00
|
|
|
prereg = create_preregistration_user(
|
|
|
|
email, request, realm_creation=False, password_required=False
|
|
|
|
)
|
|
|
|
activation_url = create_confirmation_link(prereg, Confirmation.USER_REGISTRATION)
|
2021-02-12 08:20:45 +01:00
|
|
|
key = activation_url.split("/")[-1]
|
2020-08-11 01:47:44 +02:00
|
|
|
# Need to add test data to POST request as it doesn't originally contain the required parameters
|
2021-02-12 08:20:45 +01:00
|
|
|
modify_postdata(request, key=key, full_name=name, password="test", terms="true")
|
2019-03-13 18:26:01 +01:00
|
|
|
|
|
|
|
return accounts_register(request)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-13 18:26:01 +01:00
|
|
|
@csrf_exempt
|
|
|
|
def register_development_realm(request: HttpRequest) -> HttpResponse:
|
|
|
|
count = UserProfile.objects.count()
|
2021-02-12 08:20:45 +01:00
|
|
|
name = f"user-{count}"
|
|
|
|
email = f"{name}@zulip.com"
|
|
|
|
realm_name = f"realm-{count}"
|
2021-02-12 08:19:30 +01:00
|
|
|
prereg = create_preregistration_user(
|
|
|
|
email, request, realm_creation=True, password_required=False
|
|
|
|
)
|
|
|
|
activation_url = create_confirmation_link(prereg, Confirmation.REALM_CREATION)
|
2021-02-12 08:20:45 +01:00
|
|
|
key = activation_url.split("/")[-1]
|
2020-08-11 01:47:44 +02:00
|
|
|
# Need to add test data to POST request as it doesn't originally contain the required parameters
|
2021-02-12 08:19:30 +01:00
|
|
|
modify_postdata(
|
|
|
|
request,
|
|
|
|
key=key,
|
|
|
|
realm_name=realm_name,
|
|
|
|
full_name=name,
|
2021-02-12 08:20:45 +01:00
|
|
|
password="test",
|
2021-02-12 08:19:30 +01:00
|
|
|
realm_subdomain=realm_name,
|
2021-02-12 08:20:45 +01:00
|
|
|
terms="true",
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2019-03-13 18:26:01 +01:00
|
|
|
|
|
|
|
return accounts_register(request)
|