Repository: cdriehuys/django-rest-email-auth

Issue:
Add ability to provide email verification callback
The URL template for verifying an email should be customizable. (Either as a Django setting or as a parameter to the registration endpoint)

Discussion:

Patch:
diff --git a/rest_email_auth/app_settings.py b/rest_email_auth/app_settings.py
new file mode 100644
index 0000000..51ccd0c
--- /dev/null
+++ b/rest_email_auth/app_settings.py
@@ -0,0 +1,57 @@
+"""
+Settings specific to the application.
+
+The setting implementation is modeled off of "Django Allauth's" from:
+https://github.com/pennersr/django-allauth/blob/master/allauth/account/app_settings.py
+"""
+
+
+class AppSettings(object):
+
+    def __init__(self):
+        """
+        Perform some basic settings checks.
+        """
+        # The user must provide a URL template for the verification
+        # endpoint.
+        assert self.EMAIL_VERIFICATION_URL
+
+    def _setting(self, name, default):
+        """
+        Retrieve a setting from the current Django settings.
+
+        Settings are retrieved from the ``REST_EMAIL_AUTH`` dict in the
+        settings file.
+
+        Args:
+            name (str):
+                The name of the setting to retrieve.
+            default:
+                The setting's default value.
+
+        Returns:
+            The value provided in the settings dictionary if it exists.
+            The default value is returned otherwise.
+        """
+        from django.conf import settings
+
+        settings_dict = getattr(settings, 'REST_EMAIL_AUTH', {})
+
+        return settings_dict.get(name, default)
+
+    @property
+    def EMAIL_VERIFICATION_URL(self):
+        """
+        Get the template to use for the email verification url.
+        """
+        return self._setting('EMAIL_VERIFICATION_URL', '')
+
+
+# Ugly? Guido recommends this himself ...
+# http://mail.python.org/pipermail/python-ideas/2012-May/014969.html
+import sys      # noqa
+
+
+app_settings = AppSettings()
+app_settings.__name__ = __name__
+sys.modules[__name__] = app_settings
diff --git a/rest_email_auth/models.py b/rest_email_auth/models.py
index c2c61d2..2975043 100644
--- a/rest_email_auth/models.py
+++ b/rest_email_auth/models.py
@@ -9,6 +9,8 @@ from django.utils import timezone
 from django.utils.crypto import get_random_string
 from django.utils.translation import ugettext_lazy as _
 
+from rest_email_auth import app_settings
+
 
 logger = logging.getLogger(__name__)
 
@@ -140,7 +142,8 @@ class EmailConfirmation(models.Model):
         Send a verification email to the user.
         """
         context = {
-            'confirmation': self,
+            'verification_url': app_settings.EMAIL_VERIFICATION_URL.format(
+                key=self.key),
         }
         message = render_to_string(
             context=context,
diff --git a/rest_email_auth/templates/rest_email_auth/emails/verify-email.txt b/rest_email_auth/templates/rest_email_auth/emails/verify-email.txt
index 35a879e..bad0557 100644
--- a/rest_email_auth/templates/rest_email_auth/emails/verify-email.txt
+++ b/rest_email_auth/templates/rest_email_auth/emails/verify-email.txt
@@ -1,5 +1,5 @@
 {% load i18n %}{% blocktrans %}Hello,
 
-Please verify your email address with the following key:{% endblocktrans %}
+Please click the link below to verify your email address.{% endblocktrans %}
 
-{{ confirmation.key }}
+{{ verification_url }}


Test patch:
diff --git a/rest_email_auth/tests/models/test_email_confirmation_model.py b/rest_email_auth/tests/models/test_email_confirmation_model.py
index 883156c..80e7309 100644
--- a/rest_email_auth/tests/models/test_email_confirmation_model.py
+++ b/rest_email_auth/tests/models/test_email_confirmation_model.py
@@ -5,7 +5,6 @@ try:
 except ImportError:
     import mock
 
-from django.conf import settings
 from django.template.loader import render_to_string
 
 from rest_email_auth import models
@@ -58,16 +57,23 @@ def test_is_expired_unexpired(email_confirmation_factory):
     assert not confirmation.is_expired
 
 
-def test_send(email_confirmation_factory, mailoutbox):
+def test_send(email_confirmation_factory, mailoutbox, settings):
     """
     Sending the confirmation should send an email to the associated
     email address.
     """
+    settings.REST_EMAIL_AUTH = {
+        'EMAIL_VERIFICATION_URL': 'https://example.com/verify?key={key}',
+    }
+
     confirmation = email_confirmation_factory()
     confirmation.send()
 
+    url = settings.REST_EMAIL_AUTH['EMAIL_VERIFICATION_URL'].format(
+        key=confirmation.key)
+
     context = {
-        'confirmation': confirmation,
+        'verification_url': url,
     }
     expected_content = render_to_string(
         context=context,
diff --git a/test_settings.py b/test_settings.py
index 3430e5b..4ad08ea 100644
--- a/test_settings.py
+++ b/test_settings.py
@@ -26,3 +26,9 @@ TEMPLATES = [
 
 
 ROOT_URLCONF = 'test_urls'
+
+
+# Basic settings required for the app
+REST_EMAIL_AUTH = {
+    'EMAIL_VERIFICATION_URL': 'https://example.com/verify?key={key}',
+}