2019-03-13 18:26:01 +01:00
|
|
|
from django.conf import settings
|
2019-01-11 20:56:22 +01:00
|
|
|
from django.http import HttpResponse, HttpRequest
|
2019-03-13 18:26:01 +01:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
|
|
|
from confirmation.models import Confirmation, create_confirmation_link
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from zerver.models import UserProfile
|
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
|
|
|
|
from zerver.views.auth import create_preregistration_user
|
|
|
|
from zerver.views.registration import accounts_register
|
|
|
|
|
2019-01-11 20:56:22 +01:00
|
|
|
|
|
|
|
# This is used only by the casper test in 00-realm-creation.js.
|
|
|
|
def confirmation_key(request: HttpRequest) -> HttpResponse:
|
|
|
|
return json_success(request.session.get('confirmation_key'))
|
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
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
def register_development_user(request: HttpRequest) -> HttpResponse:
|
|
|
|
if get_subdomain(request) == '':
|
|
|
|
request.META['HTTP_HOST'] = settings.REALM_HOSTS['zulip']
|
|
|
|
count = UserProfile.objects.count()
|
|
|
|
name = 'user-%d' % (count,)
|
2020-06-10 06:41:04 +02:00
|
|
|
email = f'{name}@zulip.com'
|
2019-03-13 18:26:01 +01:00
|
|
|
prereg = create_preregistration_user(email, request, realm_creation=False,
|
|
|
|
password_required=False)
|
|
|
|
activation_url = create_confirmation_link(prereg, request.get_host(),
|
|
|
|
Confirmation.USER_REGISTRATION)
|
|
|
|
key = activation_url.split('/')[-1]
|
|
|
|
# Need to add test data to POST request as it doesnt originally contain the required parameters
|
2019-08-26 22:55:55 +02: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)
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
def register_development_realm(request: HttpRequest) -> HttpResponse:
|
|
|
|
count = UserProfile.objects.count()
|
|
|
|
name = 'user-%d' % (count,)
|
2020-06-10 06:41:04 +02:00
|
|
|
email = f'{name}@zulip.com'
|
2019-03-13 18:26:01 +01:00
|
|
|
realm_name = 'realm-%d' % (count,)
|
|
|
|
prereg = create_preregistration_user(email, request, realm_creation=True,
|
|
|
|
password_required=False)
|
|
|
|
activation_url = create_confirmation_link(prereg, request.get_host(),
|
|
|
|
Confirmation.REALM_CREATION)
|
|
|
|
key = activation_url.split('/')[-1]
|
|
|
|
# Need to add test data to POST request as it doesnt originally contain the required parameters
|
|
|
|
modify_postdata(request, key=key, realm_name=realm_name, full_name=name, password='test',
|
2019-08-26 22:55:55 +02:00
|
|
|
realm_subdomain=realm_name, terms='true')
|
2019-03-13 18:26:01 +01:00
|
|
|
|
|
|
|
return accounts_register(request)
|