Skip to content

Commit

Permalink
confirmation: Use realm host in activation URLs.
Browse files Browse the repository at this point in the history
This is preparation for merging the subdomains feature.
  • Loading branch information
rishig authored and timabbott committed Aug 19, 2016
1 parent b8050ce commit 64179b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions confirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}))

Expand All @@ -71,16 +73,17 @@ def confirm(self, confirmation_key):
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,
Expand Down
2 changes: 1 addition & 1 deletion zerver/lib/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion zerver/worker/queue_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def consume(self, data):
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,
Expand Down

0 comments on commit 64179b2

Please sign in to comment.