Implement registration

This commit is contained in:
Gabriel Augendre 2022-10-31 17:08:23 +01:00
parent 881e069ed0
commit c5bfd77b34
16 changed files with 160 additions and 4 deletions

View file

@ -15,3 +15,9 @@ LOG_LEVEL=DEBUG
# SQLITE DB # SQLITE DB
############################################################################### ###############################################################################
DATABASE_URL=sqlite:////app/db/db.sqlite3 DATABASE_URL=sqlite:////app/db/db.sqlite3
###############################################################################
# EMAIL
###############################################################################
#MAILGUN_API_KEY=
MAILGUN_SENDER_DOMAIN=mg.augendre.info

View file

@ -10,3 +10,9 @@ ALLOWED_HOSTS=localhost,127.0.0.1
# LOGGING # LOGGING
############################################################################### ###############################################################################
LOG_LEVEL=DEBUG LOG_LEVEL=DEBUG
###############################################################################
# EMAIL
###############################################################################
#MAILGUN_API_KEY=
MAILGUN_SENDER_DOMAIN=mg.augendre.info

View file

@ -10,3 +10,9 @@ ALLOWED_HOSTS=localhost,127.0.0.1
# LOGGING # LOGGING
############################################################################### ###############################################################################
LOG_LEVEL=DEBUG LOG_LEVEL=DEBUG
###############################################################################
# EMAIL
###############################################################################
#MAILGUN_API_KEY=
MAILGUN_SENDER_DOMAIN=mg.augendre.info

58
poetry.lock generated
View file

@ -120,7 +120,7 @@ python-versions = ">=3.6.1"
name = "charset-normalizer" name = "charset-normalizer"
version = "2.1.1" version = "2.1.1"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
category = "dev" category = "main"
optional = false optional = false
python-versions = ">=3.6.0" python-versions = ">=3.6.0"
@ -135,6 +135,17 @@ category = "dev"
optional = false optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
[[package]]
name = "confusable-homoglyphs"
version = "3.2.0"
description = "Detect confusable usage of unicode homoglyphs, prevent homograph attacks."
category = "main"
optional = false
python-versions = "*"
[package.extras]
cli = ["click"]
[[package]] [[package]]
name = "coverage" name = "coverage"
version = "6.5.0" version = "6.5.0"
@ -194,6 +205,23 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""}
argon2 = ["argon2-cffi (>=19.1.0)"] argon2 = ["argon2-cffi (>=19.1.0)"]
bcrypt = ["bcrypt"] bcrypt = ["bcrypt"]
[[package]]
name = "django-anymail"
version = "8.6"
description = "Django email backends and webhooks for Amazon SES, Mailgun, Mailjet, Mandrill, Postal, Postmark, SendGrid, SendinBlue, and SparkPost"
category = "main"
optional = false
python-versions = ">=3.5"
[package.dependencies]
django = ">=2.0"
requests = ">=2.4.3"
[package.extras]
amazon_ses = ["boto3"]
dev = ["flake8", "sphinx", "sphinx-rtd-theme", "tox", "twine", "wheel"]
postal = ["cryptography"]
[[package]] [[package]]
name = "django-browser-reload" name = "django-browser-reload"
version = "1.6.0" version = "1.6.0"
@ -271,6 +299,18 @@ python-versions = ">=3.7"
[package.dependencies] [package.dependencies]
Django = ">=3.2" Django = ">=3.2"
[[package]]
name = "django-registration"
version = "3.3"
description = "An extensible user-registration application for Django"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
confusable-homoglyphs = ">=3.0,<4.0"
Django = ">=3.2"
[[package]] [[package]]
name = "exceptiongroup" name = "exceptiongroup"
version = "1.0.0" version = "1.0.0"
@ -708,7 +748,7 @@ python-versions = ">=3.6"
name = "requests" name = "requests"
version = "2.28.1" version = "2.28.1"
description = "Python HTTP for Humans." description = "Python HTTP for Humans."
category = "dev" category = "main"
optional = false optional = false
python-versions = ">=3.7, <4" python-versions = ">=3.7, <4"
@ -916,7 +956,7 @@ h11 = ">=0.9.0,<1"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = ">=3.10.0, <4" python-versions = ">=3.10.0, <4"
content-hash = "df8aa35ecf2515691ed8ffdccbfb63f503c9330db3cd806d7dc8a8689f64328e" content-hash = "2005841e057ea97d65b1582d1454765504d5146e98ffe5e2023e694ef093f6a4"
[metadata.files] [metadata.files]
ansicon = [ ansicon = [
@ -1029,6 +1069,10 @@ colorama = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
] ]
confusable-homoglyphs = [
{file = "confusable_homoglyphs-3.2.0-py2.py3-none-any.whl", hash = "sha256:e3ce611028d882b74a5faa69e3cbb5bd4dcd9f69936da6e73d33eda42c917944"},
{file = "confusable_homoglyphs-3.2.0.tar.gz", hash = "sha256:3b4a0d9fa510669498820c91a0bfc0c327568cecec90648cf3819d4a6fc6a751"},
]
coverage = [ coverage = [
{file = "coverage-6.5.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ef8674b0ee8cc11e2d574e3e2998aea5df5ab242e012286824ea3c6970580e53"}, {file = "coverage-6.5.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ef8674b0ee8cc11e2d574e3e2998aea5df5ab242e012286824ea3c6970580e53"},
{file = "coverage-6.5.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:784f53ebc9f3fd0e2a3f6a78b2be1bd1f5575d7863e10c6e12504f240fd06660"}, {file = "coverage-6.5.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:784f53ebc9f3fd0e2a3f6a78b2be1bd1f5575d7863e10c6e12504f240fd06660"},
@ -1130,6 +1174,10 @@ django = [
{file = "Django-4.1.2-py3-none-any.whl", hash = "sha256:26dc24f99c8956374a054bcbf58aab8dc0cad2e6ac82b0fe036b752c00eee793"}, {file = "Django-4.1.2-py3-none-any.whl", hash = "sha256:26dc24f99c8956374a054bcbf58aab8dc0cad2e6ac82b0fe036b752c00eee793"},
{file = "Django-4.1.2.tar.gz", hash = "sha256:b8d843714810ab88d59344507d4447be8b2cf12a49031363b6eed9f1b9b2280f"}, {file = "Django-4.1.2.tar.gz", hash = "sha256:b8d843714810ab88d59344507d4447be8b2cf12a49031363b6eed9f1b9b2280f"},
] ]
django-anymail = [
{file = "django-anymail-8.6.tar.gz", hash = "sha256:783342d49dd07d68778b81dd12a94c86e1d217463a68a85450a0513fabe31345"},
{file = "django_anymail-8.6-py3-none-any.whl", hash = "sha256:49d83d7c16316ca86a624097496881d59b7d71b16bf1c5211cffa5b19ef98d0c"},
]
django-browser-reload = [ django-browser-reload = [
{file = "django-browser-reload-1.6.0.tar.gz", hash = "sha256:9ca69c71796f53868bdc7421f120d147f7a64faa0d5d8c06970ba3f8061af63c"}, {file = "django-browser-reload-1.6.0.tar.gz", hash = "sha256:9ca69c71796f53868bdc7421f120d147f7a64faa0d5d8c06970ba3f8061af63c"},
{file = "django_browser_reload-1.6.0-py3-none-any.whl", hash = "sha256:31b8b2d51e8faa5878f21e6b60b8f43e1123907c6e082e9e967962ba63958829"}, {file = "django_browser_reload-1.6.0-py3-none-any.whl", hash = "sha256:31b8b2d51e8faa5878f21e6b60b8f43e1123907c6e082e9e967962ba63958829"},
@ -1158,6 +1206,10 @@ django-linear-migrations = [
{file = "django-linear-migrations-2.5.1.tar.gz", hash = "sha256:4dbba1a42ce10dc40df295f7fa2fd28d6f7b31035353f7f1a752d07c71391073"}, {file = "django-linear-migrations-2.5.1.tar.gz", hash = "sha256:4dbba1a42ce10dc40df295f7fa2fd28d6f7b31035353f7f1a752d07c71391073"},
{file = "django_linear_migrations-2.5.1-py3-none-any.whl", hash = "sha256:9b6c4157c0ee21b78affc3c9a76e89d9df7ad9239a4378d48dc7247a914f6c72"}, {file = "django_linear_migrations-2.5.1-py3-none-any.whl", hash = "sha256:9b6c4157c0ee21b78affc3c9a76e89d9df7ad9239a4378d48dc7247a914f6c72"},
] ]
django-registration = [
{file = "django-registration-3.3.tar.gz", hash = "sha256:884a4cc9ec87b9f1c0ceb6b6c4b7ba491c1877997a3cd29cc923697dac785eb8"},
{file = "django_registration-3.3-py3-none-any.whl", hash = "sha256:dfa176f594fb465c93495caa55686be723a15829769511383e25172d2efbd0e6"},
]
exceptiongroup = [ exceptiongroup = [
{file = "exceptiongroup-1.0.0-py3-none-any.whl", hash = "sha256:2ac84b496be68464a2da60da518af3785fff8b7ec0d090a581604bc870bdee41"}, {file = "exceptiongroup-1.0.0-py3-none-any.whl", hash = "sha256:2ac84b496be68464a2da60da518af3785fff8b7ec0d090a581604bc870bdee41"},
{file = "exceptiongroup-1.0.0.tar.gz", hash = "sha256:affbabf13fb6e98988c38d9c5650e701569fe3c1de3233cfb61c5f33774690ad"}, {file = "exceptiongroup-1.0.0.tar.gz", hash = "sha256:affbabf13fb6e98988c38d9c5650e701569fe3c1de3233cfb61c5f33774690ad"},

View file

@ -20,6 +20,8 @@ whitenoise = ">=6.2"
uWSGI = ">=2.0.21" uWSGI = ">=2.0.21"
selenium = ">=4.5.0" selenium = ">=4.5.0"
Markdown = ">=3.2" Markdown = ">=3.2"
django-registration = ">=3.3"
django-anymail = {extras = ["mailgun"], version = ">=8.6"}
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
django-debug-toolbar = ">=3.2" django-debug-toolbar = ">=3.2"

View file

@ -18,6 +18,9 @@ env = environ.Env(
LOG_FORMAT=(str, "default"), LOG_FORMAT=(str, "default"),
APP_DATA=(Path, PROJECT_ROOT / "data"), APP_DATA=(Path, PROJECT_ROOT / "data"),
DATABASE_URL=(str, "sqlite:////app/db/db.sqlite3"), DATABASE_URL=(str, "sqlite:////app/db/db.sqlite3"),
REGISTRATION_OPEN=(bool, True),
MAILGUN_API_KEY=(str, ""),
MAILGUN_SENDER_DOMAIN=(str, ""),
) )
env_file = os.getenv("ENV_FILE", None) env_file = os.getenv("ENV_FILE", None)
@ -200,7 +203,18 @@ AUTHENTICATION_BACKENDS = ("django.contrib.auth.backends.ModelBackend",)
LOGOUT_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/"
LOGIN_URL = "/admin/login" LOGIN_URL = "login"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
AUTH_USER_MODEL = "common.User" AUTH_USER_MODEL = "common.User"
ACCOUNT_ACTIVATION_DAYS = 2
REGISTRATION_OPEN = env("REGISTRATION_OPEN")
ANYMAIL = {
"MAILGUN_API_KEY": env("MAILGUN_API_KEY"),
"MAILGUN_SENDER_DOMAIN": env("MAILGUN_SENDER_DOMAIN"),
}
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
DEFAULT_FROM_EMAIL = "charasheet@mg.augendre.info"
SERVER_EMAIL = "charasheet@mg.augendre.info"

View file

@ -18,11 +18,20 @@ from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import logout from django.contrib.auth import logout
from django.urls import include, path from django.urls import include, path
from django_registration.backends.activation.views import RegistrationView
from common.forms import RegistrationForm
from common.views import hello_world from common.views import hello_world
urlpatterns = [ urlpatterns = [
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"), path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
path(
"accounts/register/",
RegistrationView.as_view(form_class=RegistrationForm),
name="django_registration_register",
),
path("accounts/", include("django_registration.backends.activation.urls")),
path("accounts/", include("django.contrib.auth.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("", hello_world, name="hello_world"), path("", hello_world, name="hello_world"),
path("character/", include("character.urls", namespace="character")), path("character/", include("character.urls", namespace="character")),

8
src/common/forms.py Normal file
View file

@ -0,0 +1,8 @@
import django_registration.forms
from common.models import User
class RegistrationForm(django_registration.forms.RegistrationForm):
class Meta(django_registration.forms.RegistrationForm.Meta):
model = User

View file

@ -0,0 +1,7 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Activation réussie</h1>
<p>Votre compte est désormais actif.</p>
<p><a href="{% url "login" %}" class="btn btn-primary">Se connecter</a></p>
{% endblock %}

View file

@ -0,0 +1,2 @@
Voici votre clé d'activation : https://{{ site.domain }}{% url "django_registration_activate" activation_key=activation_key %}
Elle est valable pendant {{ expiration_days }} jours.

View file

@ -0,0 +1 @@
[Character Sheet] Activation de compte

View file

@ -0,0 +1,8 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Erreur d'activation</h1>
<p>
{{ activation_error }}
</p>
{% endblock %}

View file

@ -0,0 +1,6 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Inscriptions fermées</h1>
<p>Les inscriptions sont désactivées.</p>
{% endblock %}

View file

@ -0,0 +1,6 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Inscription réussie</h1>
<p>Un e-mail permettant d'activer votre compte vous a été envoyé.</p>
{% endblock %}

View file

@ -0,0 +1,10 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Inscription</h1>
<form action="{% url "django_registration_register" %}" method="post">
{{ form.as_p }}
{% csrf_token %}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endblock %}

View file

@ -0,0 +1,13 @@
{% extends "common/base.html" %}
{% block content %}
<h1>Connexion</h1>
<form action="{% url "login" %}" method="post">
{{ form.as_p }}
{% csrf_token %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url "django_registration_register" %}" class="btn btn-secondary">
Create account
</a>
</form>
{% endblock %}