Repository: cdriehuys/django-simple-email-auth

Issue:
Allow for notifying of unnecessary sending of validation tokens
As a consumer of this app trying to implement re-sending of verification emails, it would be nice to have a `send_already_verified` method on `EmailAddress` instances that would send out an email informing the user that their email address is already verified and they should reset their password if they cannot access their account.

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index af422d9..976104a 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,14 @@
 Changelog
 #########
 
+**************
+In Development
+**************
+
+Features
+* #20: Add `EmailAddress.send_already_verified` method to send a notification to
+  the user that their email address has already been verified.
+
 ******
 v0.2.0
 ******
diff --git a/email_auth/models.py b/email_auth/models.py
index 5f0e675..5d9108c 100644
--- a/email_auth/models.py
+++ b/email_auth/models.py
@@ -129,6 +129,22 @@ class EmailAddress(models.Model):
         """
         return self.address
 
+    def send_already_verified(self):
+        """
+        Send an email notifying the user that this email address has
+        already been verified.
+        """
+        context = {"email": self}
+        template = "email_auth/emails/already-verified"
+
+        email_utils.send_email(
+            context=context,
+            from_email=settings.DEFAULT_FROM_EMAIL,
+            recipient_list=[self.address],
+            subject=_("Your Email Address has Already Been Verified"),
+            template_name=template,
+        )
+
     def send_duplicate_notification(self):
         """
         Send an email notifying the user that this email address has
diff --git a/email_auth/templates/email_auth/emails/already-verified.txt b/email_auth/templates/email_auth/emails/already-verified.txt
new file mode 100644
index 0000000..afbc20a
--- /dev/null
+++ b/email_auth/templates/email_auth/emails/already-verified.txt
@@ -0,0 +1,5 @@
+{% load i18n %}{% blocktrans with user=email.user %}Hello {{ user }},
+
+You have already verified this email address. If you are having trouble logging
+in, try resetting your password.
+{% endblocktrans %}


Test patch:
diff --git a/email_auth/test/models/test_email_address_model.py b/email_auth/test/models/test_email_address_model.py
index 0033e36..c798c73 100644
--- a/email_auth/test/models/test_email_address_model.py
+++ b/email_auth/test/models/test_email_address_model.py
@@ -51,6 +51,24 @@ def test_repr():
     assert repr(email) == expected
 
 
+@mock.patch("email_auth.models.email_utils.send_email", autospec=True)
+def test_send_already_verified(mock_send_email):
+    """
+    This method should send a notification to the email address letting
+    the user know their email address is already verified.
+    """
+    email = models.EmailAddress(address="test@example.com")
+    email.send_already_verified()
+
+    assert mock_send_email.call_args[1] == {
+        "context": {"email": email},
+        "from_email": settings.DEFAULT_FROM_EMAIL,
+        "recipient_list": [email.address],
+        "subject": "Your Email Address has Already Been Verified",
+        "template_name": "email_auth/emails/already-verified",
+    }
+
+
 @mock.patch("email_auth.models.email_utils.send_email", autospec=True)
 def test_send_duplicate_notification(mock_send_email):
     """