From 17fd72e9f855426d1f9bc8ef9f1dc2d86eb58315 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 26 Sep 2023 10:26:11 -0700 Subject: [PATCH] Support password reset hide link if not enabled --- docs/configuration.md | 29 ++++++++ docs/usage.md | 5 ++ src/documents/context_processors.py | 8 +++ src/documents/static/signin.css | 25 +++++-- .../templates/registration/login.html | 5 ++ .../registration/password_reset_complete.html | 45 ++++++++++++ .../registration/password_reset_confirm.html | 70 +++++++++++++++++++ .../registration/password_reset_done.html | 44 ++++++++++++ .../registration/password_reset_form.html | 58 +++++++++++++++ src/paperless/settings.py | 13 ++++ 10 files changed, 295 insertions(+), 7 deletions(-) create mode 100644 src/documents/context_processors.py create mode 100644 src/documents/templates/registration/password_reset_complete.html create mode 100644 src/documents/templates/registration/password_reset_confirm.html create mode 100644 src/documents/templates/registration/password_reset_done.html create mode 100644 src/documents/templates/registration/password_reset_form.html diff --git a/docs/configuration.md b/docs/configuration.md index 88c8a5094..f59863bb0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1301,3 +1301,32 @@ started by the container. v1.9.2. A one-time migration is performed for users who have this setting set. This setting is always ignored if the corresponding frontend setting has been set. + +## Email sending + +Setting an SMTP server for the backend will allow you to reset your +password. All of these options come from their similarly-named [Django settings](https://docs.djangoproject.com/en/1.8/ref/settings/#email-host) + +#### [`PAPERLESS_EMAIL_HOST=`](#PAPERLESS_EMAIL_HOST) {#PAPERLESS_EMAIL_HOST} + +: Defaults to 'localhost'. + +#### [`PAPERLESS_EMAIL_PORT=`](#PAPERLESS_EMAIL_PORT) {#PAPERLESS_EMAIL_PORT} + +: Defaults to port 25. + +#### [`PAPERLESS_EMAIL_USER=`](#PAPERLESS_EMAIL_USER) {#PAPERLESS_EMAIL_USER} + +: Defaults to ''. + +#### [`PAPERLESS_EMAIL_PASSWORD=`](#PAPERLESS_EMAIL_PASSWORD) {#PAPERLESS_EMAIL_PASSWORD} + +: Defaults to ''. + +#### [`PAPERLESS_EMAIL_USE_TLS=`](#PAPERLESS_EMAIL_USE_TLS) {#PAPERLESS_EMAIL_USE_TLS} + +: Defaults to false. + +#### [`PAPERLESS_EMAIL_USE_SSL=`](#PAPERLESS_EMAIL_USE_SSL) {#PAPERLESS_EMAIL_USE_SSL} + +: Defaults to false. diff --git a/docs/usage.md b/docs/usage.md index 340a1f2c3..aad4976f8 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -261,6 +261,11 @@ These can be found under Settings > Users & Groups, assuming the user has access as a member of a group those permissions will be inherited and this is reflected in the UI. Explicit permissions can be granted to limit access to certain parts of the UI (and corresponding API endpoints). +### Password reset + +In order to enable the password reset feature you will need to setup an SMTP backend, see +[`PAPERLESS_EMAIL_HOST`](/configuration#PAPERLESS_EMAIL_HOST) + ## Consumption templates Consumption templates were introduced in v2.0 and allow for finer control over what metadata (tags, doc diff --git a/src/documents/context_processors.py b/src/documents/context_processors.py new file mode 100644 index 000000000..90c856aeb --- /dev/null +++ b/src/documents/context_processors.py @@ -0,0 +1,8 @@ +from django.conf import settings as django_settings + + +def settings(request): + return { + "EMAIL_ENABLED": django_settings.EMAIL_HOST != "localhost" + or django_settings.EMAIL_HOST_USER != "", + } diff --git a/src/documents/static/signin.css b/src/documents/static/signin.css index 7115adae2..02f460c7c 100644 --- a/src/documents/static/signin.css +++ b/src/documents/static/signin.css @@ -2,32 +2,43 @@ body { --bs-body-bg: #f5f5f5; --bs-link-color-rgb: 23, 84, 31; /* #17541f */ --bs-link-hover-color-rgb: 15, 56, 20; + --pngx-primary: #17541f; + --pngx-primary-hover: #0f3614; + --pngx-primary-active: #0c2c10; } .form-control { --bs-body-bg: #fff; } -.btn { - --bs-btn-bg: #17541f; - --bs-btn-border-color: #17541f; - --bs-btn-hover-bg: #0f3614; +.btn.btn-primary { + --bs-btn-bg: var(--pngx-primary); + --bs-btn-border-color: var(--pngx-primary); + --bs-btn-hover-bg: var(--pngx-primary-hover); --bs-btn-hover-border-color: #0c2c10; - --bs-btn-active-bg: #0c2c10; + --bs-btn-active-bg: var(--pngx-primary-active); --bs-btn-active-border-color: #09220d; } +.btn-link { + --bs-btn-color: var(--pngx-primary); + --bs-btn-hover-color: var(--pngx-primary-hover); + --bs-btn-active-color: var(--pngx-primary-active); +} + .form-signin { max-width: 330px; } -#inputUsername { +#inputUsername, +#inputPassword1 { margin-bottom: -1px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } -#inputPassword { +#inputPassword, +#inputPassword2 { border-top-left-radius: 0; border-top-right-radius: 0; } diff --git a/src/documents/templates/registration/login.html b/src/documents/templates/registration/login.html index c4c936182..ba57013ac 100644 --- a/src/documents/templates/registration/login.html +++ b/src/documents/templates/registration/login.html @@ -65,6 +65,11 @@
+ {% if EMAIL_ENABLED %} + + {% endif %} diff --git a/src/documents/templates/registration/password_reset_complete.html b/src/documents/templates/registration/password_reset_complete.html new file mode 100644 index 000000000..d9b0a3b72 --- /dev/null +++ b/src/documents/templates/registration/password_reset_complete.html @@ -0,0 +1,45 @@ + + +{% load static %} +{% load i18n %} + + + + + + + + + + {% translate "Paperless-ngx reset password complete" %} + + + + + + +
+ +

{% translate "Password reset complete." %}

+ {% url 'login' as login_url %} +

{% blocktranslate %}Your new password has been set. You can now log in{% endblocktranslate %}.

+
+ + diff --git a/src/documents/templates/registration/password_reset_confirm.html b/src/documents/templates/registration/password_reset_confirm.html new file mode 100644 index 000000000..8f24212a7 --- /dev/null +++ b/src/documents/templates/registration/password_reset_confirm.html @@ -0,0 +1,70 @@ + + +{% load static %} +{% load i18n %} + + + + + + + + + + {% translate "Paperless-ngx reset password confirmation" %} + + + + + + + + + diff --git a/src/documents/templates/registration/password_reset_done.html b/src/documents/templates/registration/password_reset_done.html new file mode 100644 index 000000000..b798ee324 --- /dev/null +++ b/src/documents/templates/registration/password_reset_done.html @@ -0,0 +1,44 @@ + + +{% load static %} +{% load i18n %} + + + + + + + + + + {% translate "Paperless-ngx reset password sent" %} + + + + + + +
+ +

{% translate "Check your inbox." %}

+

{% translate "We've emailed you instructions for setting your password. You should receive the email shortly!" %}

+
+ + diff --git a/src/documents/templates/registration/password_reset_form.html b/src/documents/templates/registration/password_reset_form.html new file mode 100644 index 000000000..9bdc22943 --- /dev/null +++ b/src/documents/templates/registration/password_reset_form.html @@ -0,0 +1,58 @@ + + +{% load static %} +{% load i18n %} + + + + + + + + + + {% translate "Paperless-ngx reset password request" %} + + + + + + + + + diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 6d25a53cc..f3cbb6ee2 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -357,6 +357,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "documents.context_processors.settings", ], }, }, @@ -1002,3 +1003,15 @@ def _get_nltk_language_setting(ocr_lang: str) -> Optional[str]: NLTK_ENABLED: Final[bool] = __get_boolean("PAPERLESS_ENABLE_NLTK", "yes") NLTK_LANGUAGE: Optional[str] = _get_nltk_language_setting(OCR_LANGUAGE) + +############################################################################### +# Email (SMTP) Backend # +############################################################################### + +EMAIL_HOST: Final[str] = os.getenv("PAPERLESS_EMAIL_HOST", "localhost") +EMAIL_PORT: Final[int] = int(os.getenv("PAPERLESS_EMAIL_PORT", 25)) +EMAIL_HOST_USER: Final[str] = os.getenv("PAPERLESS_EMAIL_HOST_USER", "") +EMAIL_HOST_PASSWORD: Final[str] = os.getenv("PAPERLESS_EMAIL_HOST_PASSWORD", "") +EMAIL_USE_TLS: Final[bool] = __get_boolean("PAPERLESS_EMAIL_USE_TLS") +EMAIL_USE_SSL: Final[bool] = __get_boolean("PAPERLESS_EMAIL_USE_SSL") +EMAIL_SUBJECT_PREFIX: Final[str] = "[Paperless-ngx] "