From ab4eb7414c519202d78ba2546d4603bd1ee0d3e5 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 4 Feb 2018 01:36:39 +0100 Subject: [PATCH] Add basic user functionalities Users need to register, login, logout and reset their password. --- README.md | 10 ++ khaganat/settings.py | 17 ++ khaganat/templates/khaganat/base.html | 4 +- khaganat/templates/khaganat/email.html | 11 ++ khaganat/urls.py | 1 + logs/locale/en/LC_MESSAGES/django.po | 6 +- logs/locale/fr/LC_MESSAGES/django.po | 6 +- navbar/templates/navbar/navbar.html | 23 ++- navbar/templatetags/navbar.py | 2 + neluser/forms.py | 9 + neluser/locale/en/LC_MESSAGES/django.po | 155 +++++++++++++++++ neluser/locale/fr/LC_MESSAGES/django.po | 160 ++++++++++++++++++ neluser/models.py | 4 +- neluser/templates/neluser/activate_done.html | 13 ++ neluser/templates/neluser/activate_email.html | 16 ++ neluser/templates/neluser/activate_email.txt | 12 ++ .../neluser/activate_email_subject.txt | 3 + neluser/templates/neluser/login.html | 17 ++ neluser/templates/neluser/password_reset.html | 14 ++ .../neluser/password_reset_confirm.html | 19 +++ .../neluser/password_reset_done.html | 10 ++ .../neluser/password_reset_email.html | 16 ++ .../neluser/password_reset_email.txt | 12 ++ .../neluser/password_reset_email_subject.txt | 3 + neluser/templates/neluser/register.html | 14 ++ neluser/templates/neluser/register_done.html | 13 ++ neluser/urls.py | 64 +++++++ neluser/views.py | 73 +++++++- 28 files changed, 694 insertions(+), 13 deletions(-) create mode 100644 khaganat/templates/khaganat/email.html create mode 100644 neluser/forms.py create mode 100644 neluser/locale/en/LC_MESSAGES/django.po create mode 100644 neluser/locale/fr/LC_MESSAGES/django.po create mode 100644 neluser/templates/neluser/activate_done.html create mode 100644 neluser/templates/neluser/activate_email.html create mode 100644 neluser/templates/neluser/activate_email.txt create mode 100644 neluser/templates/neluser/activate_email_subject.txt create mode 100644 neluser/templates/neluser/login.html create mode 100644 neluser/templates/neluser/password_reset.html create mode 100644 neluser/templates/neluser/password_reset_confirm.html create mode 100644 neluser/templates/neluser/password_reset_done.html create mode 100644 neluser/templates/neluser/password_reset_email.html create mode 100644 neluser/templates/neluser/password_reset_email.txt create mode 100644 neluser/templates/neluser/password_reset_email_subject.txt create mode 100644 neluser/templates/neluser/register.html create mode 100644 neluser/templates/neluser/register_done.html create mode 100644 neluser/urls.py diff --git a/README.md b/README.md index c5af1b8..df8ce64 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,13 @@ You can set the following variables in the `.env` file: * `KHAGANAT_STATIC_ROOT`: Absolute path to the directory where static files should be collected. * `KHAGANAT_LOGS_MIN_DAYS`: Numbers of days before logs are hidden, default is 7. * `KHAGANAT_LOGS_MAX_DAYS`: Number of days before logs are published, default is 0. +* `KHAGANAT_LOGIN_URL`: The login URL, default is `/account/login/`. +* `KHAGANAT_LOGIN_REDIRECT_URL`: URL to redirect after user login. Will be reversed, default is `index`. +* `KHAGANAT_REGISTER_REQUIRE_VALIDATION`: require email validation upon registration, default is true. +* `KHAGANAT_EMAIL_HOST`: The host to use for sending email, default is `localhost`. +* `KHAGANAT_EMAIL_PORT`: Port to use for the SMTP server, default is `25`. +* `KHAGANAT_EMAIL_HOST_USER`: Username to use for the SMTP server, default is empty (no authentication). +* `KHAGANAT_EMAIL_HOST_PASSWORD`: Password to use for the SMTP server, default is empty. +* `KHAGANAT_EMAIL_USE_TLS`: Whether to use a TLS connection to the SMTP server, default is `False`. +* `KHAGANAT_EMAIL_SUBJECT_PREFIX`: Subject-line prefix for email, default is empty. +* `KHAGANAT_DEFAULT_FROM_EMAIL`: Default email address to use, default is `no-reply@localhost`. diff --git a/khaganat/settings.py b/khaganat/settings.py index ed34c59..756e55e 100644 --- a/khaganat/settings.py +++ b/khaganat/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ """ from django.utils.translation import gettext_lazy as _ +from django.urls import reverse_lazy import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -91,10 +92,26 @@ DATABASES = { } +# Emailing +# https://docs.djangoproject.com/fr/2.0/topics/email/ + +EMAIL_HOST = os.getenv('KHAGANAT_EMAIL_HOST', default='localhost') +EMAIL_PORT = int(os.getenv('KHAGANAT_EMAIL_PORT', default='25')) +EMAIL_HOST_USER = os.getenv('KHAGANAT_EMAIL_HOST_USER', default='') +EMAIL_HOST_PASSWORD = os.getenv('KHAGANAT_EMAIL_HOST_PASSWORD', default='') +EMAIL_USE_TLS = os.getenv('KHAGANAT_EMAIL_USE_TLS', default='') + +EMAIL_SUBJECT_PREFIX = os.getenv('KHAGANAT_EMAIL_SUBJECT_PREFIX', default='') +DEFAULT_FROM_EMAIL = os.getenv('KHAGANAT_DEFAULT_FROM_EMAIL', default='no-reply@localhost') + + # User model # https://docs.djangoproject.com/en/2.0/topics/auth/customizing/ AUTH_USER_MODEL = 'neluser.NelUser' +LOGIN_URL = os.getenv('KHAGANAT_LOGIN_URL', default='/account/login/') +LOGIN_REDIRECT_URL = reverse_lazy(os.getenv('KHAGANAT_LOGIN_REDIRECT_URL', default='index')) +REGISTER_REQUIRE_VALIDATION = bool(os.getenv('KHAGANAT_REGISTER_REQUIRE_VALIDATION', default='True')) # Password validation diff --git a/khaganat/templates/khaganat/base.html b/khaganat/templates/khaganat/base.html index db16ff8..396db7b 100644 --- a/khaganat/templates/khaganat/base.html +++ b/khaganat/templates/khaganat/base.html @@ -1,5 +1,5 @@ -{% load static %}{% load navbar %} - +{% load static %}{% load i18n %}{% load navbar %}{% get_current_language as LANGUAGE_CODE %} + diff --git a/khaganat/templates/khaganat/email.html b/khaganat/templates/khaganat/email.html new file mode 100644 index 0000000..4a306e5 --- /dev/null +++ b/khaganat/templates/khaganat/email.html @@ -0,0 +1,11 @@ +{% load i18n %}{% get_current_language as LANGUAGE_CODE %} + + + + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/khaganat/urls.py b/khaganat/urls.py index 7fcae03..6026466 100644 --- a/khaganat/urls.py +++ b/khaganat/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ urlpatterns += i18n_patterns( path('', index), path('admin/', admin.site.urls), + path('account/', include('neluser.urls')), path('page/', include('pages.urls')), path('logs/', include('logs.urls')), ) diff --git a/logs/locale/en/LC_MESSAGES/django.po b/logs/locale/en/LC_MESSAGES/django.po index f41c716..c8e6fa8 100644 --- a/logs/locale/en/LC_MESSAGES/django.po +++ b/logs/locale/en/LC_MESSAGES/django.po @@ -3,10 +3,10 @@ msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-01-27 18:32+0100\n" -"PO-Revision-Date: 2018-01-27 18:35+1\n" -"Last-Translator: Rodolphe Bréard \n" +"PO-Revision-Date: 2018-01-27 18:35+0100\n" +"Last-Translator: Khaganat \n" "Language-Team: Khaganat \n" -"Language: English\n" +"Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/logs/locale/fr/LC_MESSAGES/django.po b/logs/locale/fr/LC_MESSAGES/django.po index 8ebd924..e893b0b 100644 --- a/logs/locale/fr/LC_MESSAGES/django.po +++ b/logs/locale/fr/LC_MESSAGES/django.po @@ -3,10 +3,10 @@ msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-01-27 18:32+0100\n" -"PO-Revision-Date: 2018-01-27 18:35+1\n" -"Last-Translator: Rodolphe Bréard \n" +"PO-Revision-Date: 2018-01-27 18:35+0100\n" +"Last-Translator: Khaganat \n" "Language-Team: Khaganat \n" -"Language: Français\n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/navbar/templates/navbar/navbar.html b/navbar/templates/navbar/navbar.html index 6045375..bf89faa 100644 --- a/navbar/templates/navbar/navbar.html +++ b/navbar/templates/navbar/navbar.html @@ -1,4 +1,7 @@ -{% load static %}