Skip to content

Commit

Permalink
Add time validation for email confirmations.
Browse files Browse the repository at this point in the history
Adds a function which returns the number of days for which
a confirmation link will remain valid. This function can be
overridden by derived classes to provide a different value.
  • Loading branch information
umairwaheed authored and timabbott committed Feb 8, 2017
1 parent 8b2d4f1 commit f4b242e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions confirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def confirm(self, confirmation_key):
confirmation = self.get(confirmation_key=confirmation_key)
except self.model.DoesNotExist:
return False

max_days = self.get_link_validity_in_days()
time_elapsed = now() - confirmation.date_sent
if time_elapsed.total_seconds() > max_days * 24 * 3600:
return False

obj = confirmation.content_object
status_field = get_status_field(obj._meta.app_label, obj._meta.model_name)
setattr(obj, status_field, getattr(settings, 'STATUS_ACTIVE', 1))
Expand All @@ -82,6 +88,10 @@ def get_activation_url(self, confirmation_key, host=None):
# type: (Text, Optional[str]) -> Text
return generate_activation_url(confirmation_key, host=host)

def get_link_validity_in_days(self):
# type: () -> int
return getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10)

def send_confirmation(self, obj, email_address, additional_context=None,
subject_template_path=None, body_template_path=None,
host=None):
Expand Down

0 comments on commit f4b242e

Please sign in to comment.