Skip to content

Commit

Permalink
confirmation: Move check_prereg_key_and_redirect to registration.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
rishig authored and timabbott committed Nov 30, 2017
1 parent 6e8f4ff commit 7c96940
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
34 changes: 0 additions & 34 deletions confirmation/views.py

This file was deleted.

20 changes: 20 additions & 0 deletions zerver/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@

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']
Expand Down
3 changes: 1 addition & 2 deletions zproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import zerver.views.user_settings
import zerver.views.muting
import zerver.views.streams
import confirmation.views

from zerver.lib.rest import rest_dispatch

Expand Down Expand Up @@ -411,7 +410,7 @@
url(r'^accounts/register/', zerver.views.registration.accounts_register,
name='zerver.views.registration.accounts_register'),
url(r'^accounts/do_confirm/(?P<confirmation_key>[\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<confirmation_key>[\w]+)',
Expand Down

0 comments on commit 7c96940

Please sign in to comment.