registration: Track create organization page in GA.

This will help us track if users actually clicked on the
email confirmation link while creating a new organization.

Replaced all the `reder` calls in `accounts_register` with
`TemplateResponse` to comply with `add_google_analytics`
decorator.
This commit is contained in:
Aman Agrawal 2023-02-01 07:05:01 +00:00 committed by Tim Abbott
parent 0f155b597f
commit 9965ad2ea3
3 changed files with 15 additions and 12 deletions

View File

@ -13,7 +13,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import CASCADE
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.timezone import now as timezone_now
@ -43,10 +43,10 @@ def render_confirmation_key_error(
request: HttpRequest, exception: ConfirmationKeyError
) -> HttpResponse:
if exception.error_type == ConfirmationKeyError.WRONG_LENGTH:
return render(request, "confirmation/link_malformed.html", status=404)
return TemplateResponse(request, "confirmation/link_malformed.html", status=404)
if exception.error_type == ConfirmationKeyError.EXPIRED:
return render(request, "confirmation/link_expired.html", status=404)
return render(request, "confirmation/link_does_not_exist.html", status=404)
return TemplateResponse(request, "confirmation/link_expired.html", status=404)
return TemplateResponse(request, "confirmation/link_does_not_exist.html", status=404)
def generate_key() -> str:

View File

@ -17,7 +17,7 @@ from django.core.validators import validate_email
from django.forms import Form
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, HttpResponseServerError
from django.shortcuts import redirect, render
from django.template.response import SimpleTemplateResponse
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.urls import reverse
from django.utils.html import escape
from django.utils.http import url_has_allowed_host_and_scheme
@ -365,7 +365,7 @@ def finish_desktop_flow(request: HttpRequest, user_profile: UserProfile, otp: st
"browser_url": reverse("login_page", kwargs={"template_name": "zerver/login.html"}),
"realm_icon_url": realm_icon_url(user_profile.realm),
}
return render(request, "zerver/desktop_redirect.html", context=context)
return TemplateResponse(request, "zerver/desktop_redirect.html", context=context)
def finish_mobile_flow(request: HttpRequest, user_profile: UserProfile, otp: str) -> HttpResponse:

View File

@ -147,6 +147,7 @@ def check_prereg_key(request: HttpRequest, confirmation_key: str) -> Preregistra
return prereg_user
@add_google_analytics
@require_post
@has_request_variables
def accounts_register(
@ -175,7 +176,9 @@ def accounts_register(
try:
validators.validate_email(email)
except ValidationError:
return render(request, "zerver/invalid_email.html", context={"invalid_email": True})
return TemplateResponse(
request, "zerver/invalid_email.html", context={"invalid_email": True}
)
if realm_creation:
# For creating a new realm, there is no existing realm or domain
@ -190,19 +193,19 @@ def accounts_register(
try:
email_allowed_for_realm(email, realm)
except DomainNotAllowedForRealmError:
return render(
return TemplateResponse(
request,
"zerver/invalid_email.html",
context={"realm_name": realm.name, "closed_domain": True},
)
except DisposableEmailError:
return render(
return TemplateResponse(
request,
"zerver/invalid_email.html",
context={"realm_name": realm.name, "disposable_emails_not_allowed": True},
)
except EmailContainsPlusError:
return render(
return TemplateResponse(
request,
"zerver/invalid_email.html",
context={"realm_name": realm.name, "email_contains_plus": True},
@ -222,7 +225,7 @@ def accounts_register(
try:
check_spare_licenses_available_for_registering_new_user(realm, email, role=role)
except LicenseLimitError:
return render(request, "zerver/no_spare_licenses.html")
return TemplateResponse(request, "zerver/no_spare_licenses.html")
name_validated = False
require_ldap_password = False
@ -491,7 +494,7 @@ def accounts_register(
assert isinstance(auth_result, UserProfile)
return login_and_go_to_home(request, auth_result)
return render(
return TemplateResponse(
request,
"zerver/register.html",
context={