confirmation: Use realm host in activation URLs.

This is preparation for merging the subdomains feature.
This commit is contained in:
Rishi Gupta 2016-08-12 14:19:34 -07:00 committed by Tim Abbott
parent b8050ce02f
commit 64179b2fd2
3 changed files with 11 additions and 8 deletions

View File

@ -42,9 +42,11 @@ def check_key_is_valid(creation_key):
def generate_key():
return generate_random_token(40)
def generate_activation_url(key):
def generate_activation_url(key, host=None):
if host is None:
host = settings.EXTERNAL_HOST
return u'%s%s%s' % (settings.EXTERNAL_URI_SCHEME,
settings.EXTERNAL_HOST,
host,
reverse('confirmation.views.confirm',
kwargs={'confirmation_key': key}))
@ -71,16 +73,17 @@ class ConfirmationManager(models.Manager):
return obj
return False
def get_link_for_object(self, obj):
def get_link_for_object(self, obj, host=None):
key = generate_key()
self.create(content_object=obj, date_sent=now(), confirmation_key=key)
return generate_activation_url(key)
return generate_activation_url(key, host=host)
def send_confirmation(self, obj, email_address, additional_context=None,
subject_template_path=None, body_template_path=None):
subject_template_path=None, body_template_path=None,
host=None):
confirmation_key = generate_key()
current_site = Site.objects.get_current()
activate_url = generate_activation_url(confirmation_key)
activate_url = generate_activation_url(confirmation_key, host=host)
context = Context({
'activate_url': activate_url,
'current_site': current_site,

View File

@ -3031,7 +3031,7 @@ def do_send_confirmation_email(invitee, referrer):
Confirmation.objects.send_confirmation(
invitee, invitee.email, additional_context=context,
subject_template_path=subject_template_path,
body_template_path=body_template_path)
body_template_path=body_template_path, host=referrer.realm.host)
@statsd_increment("push_notifications")
def handle_push_notification(user_profile_id, missed_message):

View File

@ -151,7 +151,7 @@ class ConfirmationEmailWorker(QueueProcessingWorker):
do_send_confirmation_email(invitee, referrer)
# queue invitation reminder for two days from now.
link = Confirmation.objects.get_link_for_object(invitee)
link = Confirmation.objects.get_link_for_object(invitee, host=referrer.realm.host)
send_local_email_template_with_delay([{'email': data["email"], 'name': ""}],
"zerver/emails/invitation/invitation_reminder_email",
{'activate_url': link,