-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow for using links over raw tokens.
Instead of providing the raw tokens for email verifications and password resets, users can now configure the app to send links to other web pages. Closes #32
- Loading branch information
Showing
15 changed files
with
299 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
:caption: Contents: | ||
|
||
installation | ||
settings | ||
templates | ||
changelog-proxy | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.. _app-settings: | ||
|
||
######## | ||
Settings | ||
######## | ||
|
||
Settings are provided as a dictionary named ``EMAIL_AUTH`` in the Django | ||
settings file. For example:: | ||
|
||
# settings.py | ||
|
||
EMAIL_AUTH = { | ||
"EMAIL_VERIFICATION_URL": "https://example.com/{key}" | ||
} | ||
|
||
.. _email-verification-url: | ||
|
||
************************** | ||
``EMAIL_VERIFICATION_URL`` | ||
************************** | ||
|
||
Default | ||
``None`` | ||
|
||
Example | ||
``https://my-frontend.com/verify-email/{key}`` | ||
|
||
A template used to construct the URL of the page that users visit to verify | ||
their email. The placeholder ``{key}`` will be replaced with the verification | ||
token. | ||
|
||
.. _password-reset-url: | ||
|
||
********************** | ||
``PASSWORD_RESET_URL`` | ||
********************** | ||
|
||
Default | ||
``None`` | ||
|
||
Example | ||
``https://my-frontend.com/reset-password/{key}`` | ||
|
||
A template used to construct the URL of the page that users visit to reset their | ||
password. The placeholder ``{key}`` will be replaced with the reset token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Settings specific to ``simple_email_auth``. | ||
The setting implementation is modeled on "Django Allauth's" from: | ||
https://github.com/pennersr/django-allauth/blob/master/allauth/account/app_settings.py | ||
""" | ||
|
||
import sys | ||
from typing import Optional | ||
|
||
|
||
class AppSettings(object): | ||
def _setting(self, name: str, default: any): | ||
""" | ||
Retrieve a setting from the current Django settings. | ||
Settings are retrieved from the ``EMAIL_AUTH`` dict in the | ||
settings file. | ||
Args: | ||
name: | ||
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, "EMAIL_AUTH", {}) | ||
|
||
return settings_dict.get(name, default) | ||
|
||
@property | ||
def EMAIL_VERIFICATION_URL(self) -> Optional[str]: | ||
""" | ||
The template to use for the email verification url. | ||
""" | ||
return self._setting("EMAIL_VERIFICATION_URL", None) | ||
|
||
@property | ||
def PASSWORD_RESET_URL(self) -> Optional[str]: | ||
""" | ||
The template to use for the password reset url. | ||
""" | ||
return self._setting("PASSWORD_RESET_URL", None) | ||
|
||
|
||
# Ugly? Guido recommends this himself ... | ||
# http://mail.python.org/pipermail/python-ideas/2012-May/014969.html | ||
|
||
app_settings = AppSettings() | ||
app_settings.__name__ = __name__ | ||
sys.modules[__name__] = app_settings |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
default_app_config = ( | ||
"email_auth.interfaces.rest.apps.EmailAuthRESTInterfaceConfig" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
class EmailAuthRESTInterfaceConfig(AppConfig): | ||
""" | ||
Default configuration for ``email_auth.interfaces.rest``. | ||
""" | ||
|
||
name = "email_auth.interfaces.rest" | ||
verbose_name = _("Simple Email Authentication REST Interface") |
6 changes: 6 additions & 0 deletions
6
email_auth/interfaces/rest/templates/email_auth/emails/reset-password.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% load i18n %}{% blocktrans with user=password_reset.email.user %}Hello {{ user }}, | ||
|
||
Please reset your password using the following link: | ||
|
||
{{ reset_url }} | ||
{% endblocktrans %} |
6 changes: 6 additions & 0 deletions
6
email_auth/interfaces/rest/templates/email_auth/emails/verify-email.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% load i18n %}{% blocktrans %}Hello {{ user }}, | ||
|
||
Please visit the following URL to verify your email address: | ||
|
||
{{ verification_url }} | ||
{% endblocktrans %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.