From 7c9694077e4e209de3ff2d2e4d1932447decf76e Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Wed, 29 Nov 2017 20:07:18 -0800 Subject: [PATCH] confirmation: Move check_prereg_key_and_redirect to registration.py. --- confirmation/views.py | 34 ---------------------------------- zerver/views/registration.py | 20 ++++++++++++++++++++ zproject/urls.py | 3 +-- 3 files changed, 21 insertions(+), 36 deletions(-) delete mode 100644 confirmation/views.py diff --git a/confirmation/views.py b/confirmation/views.py deleted file mode 100644 index 2133c069e4..0000000000 --- a/confirmation/views.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright: (c) 2008, Jarek Zgoda - -__revision__ = '$Id: views.py 21 2008-12-05 09:21:03Z jarek.zgoda $' - - -from django.shortcuts import render -from django.http import HttpRequest, HttpResponse - -from confirmation.models import Confirmation, get_object_from_key, ConfirmationKeyException, \ - render_confirmation_key_error - -from typing import Any, Dict - -def check_prereg_key_and_redirect(request: HttpRequest, confirmation_key: str) -> HttpResponse: - # If the key isn't valid, show the error message on the original URL - confirmation = Confirmation.objects.filter(confirmation_key=confirmation_key).first() - if confirmation is None or confirmation.type not in [ - Confirmation.USER_REGISTRATION, Confirmation.INVITATION, Confirmation.REALM_CREATION]: - return render_confirmation_key_error( - request, ConfirmationKeyException(ConfirmationKeyException.DOES_NOT_EXIST)) - try: - get_object_from_key(confirmation_key, confirmation.type) - except ConfirmationKeyException as exception: - return render_confirmation_key_error(request, exception) - - # confirm_preregistrationuser.html just extracts the confirmation_key - # (and GET parameters) and redirects to /accounts/register, so that the - # user can enter their information on a cleaner URL. - return render(request, 'confirmation/confirm_preregistrationuser.html', - context={ - 'key': confirmation_key, - 'full_name': request.GET.get("full_name", None)}) diff --git a/zerver/views/registration.py b/zerver/views/registration.py index a61671721c..e70ed62bac 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -47,6 +47,26 @@ import ujson import urllib +def check_prereg_key_and_redirect(request: HttpRequest, confirmation_key: str) -> HttpResponse: + # If the key isn't valid, show the error message on the original URL + confirmation = Confirmation.objects.filter(confirmation_key=confirmation_key).first() + if confirmation is None or confirmation.type not in [ + Confirmation.USER_REGISTRATION, Confirmation.INVITATION, Confirmation.REALM_CREATION]: + return render_confirmation_key_error( + request, ConfirmationKeyException(ConfirmationKeyException.DOES_NOT_EXIST)) + try: + get_object_from_key(confirmation_key, confirmation.type) + except ConfirmationKeyException as exception: + return render_confirmation_key_error(request, exception) + + # confirm_preregistrationuser.html just extracts the confirmation_key + # (and GET parameters) and redirects to /accounts/register, so that the + # user can enter their information on a cleaner URL. + return render(request, 'confirmation/confirm_preregistrationuser.html', + context={ + 'key': confirmation_key, + 'full_name': request.GET.get("full_name", None)}) + @require_post def accounts_register(request: HttpRequest) -> HttpResponse: key = request.POST['key'] diff --git a/zproject/urls.py b/zproject/urls.py index d8e60a71a7..67bddd5309 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -31,7 +31,6 @@ import zerver.views.user_groups import zerver.views.user_settings import zerver.views.muting import zerver.views.streams -import confirmation.views from zerver.lib.rest import rest_dispatch @@ -411,7 +410,7 @@ i18n_urls = [ url(r'^accounts/register/', zerver.views.registration.accounts_register, name='zerver.views.registration.accounts_register'), url(r'^accounts/do_confirm/(?P[\w]+)', - confirmation.views.check_prereg_key_and_redirect, + zerver.views.registration.check_prereg_key_and_redirect, name='check_prereg_key_and_redirect'), url(r'^accounts/confirm_new_email/(?P[\w]+)',