mirror of
https://github.com/Crocmagnon/cookiecutter-django.git
synced 2024-11-05 06:23:54 +01:00
Pre-configure registration & browser reload
This commit is contained in:
parent
8a015f1cef
commit
28006feeb0
11 changed files with 114 additions and 4 deletions
|
@ -3,6 +3,10 @@
|
|||
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
|
||||
"python_version": "3.11.1",
|
||||
"_copy_without_render": [
|
||||
"*.html"
|
||||
"*.html",
|
||||
"*/activation*.txt"
|
||||
],
|
||||
"_extensions": [
|
||||
"cookiecutter.extensions.RandomStringExtension"
|
||||
]
|
||||
}
|
||||
|
|
8
{{cookiecutter.project_slug}}/src/common/forms.py
Normal file
8
{{cookiecutter.project_slug}}/src/common/forms.py
Normal 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
|
|
@ -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 %}
|
|
@ -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.
|
|
@ -0,0 +1 @@
|
|||
[{{cookiecutter.project_name}}] Activation de compte
|
|
@ -0,0 +1,8 @@
|
|||
{% extends "common/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Erreur d'activation</h1>
|
||||
<p>
|
||||
{{ activation_error }}
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,6 @@
|
|||
{% extends "common/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Inscriptions fermées</h1>
|
||||
<p>Les inscriptions sont désactivées.</p>
|
||||
{% endblock %}
|
|
@ -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 %}
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "common/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Inscription</h1>
|
||||
<form action="{% url "django_registration_register" %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="S'inscrire">
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -14,14 +14,19 @@ CONTRIB_DIR = PROJECT_ROOT / "contrib"
|
|||
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False),
|
||||
SECRET_KEY=str,
|
||||
SECRET_KEY=(str, "{{ random_ascii_string(50, punctuation=True) }}"),
|
||||
ALLOWED_HOSTS=(list, []),
|
||||
DEBUG_TOOLBAR=(bool, True),
|
||||
STATIC_ROOT=(Path, BASE_DIR / "public" / "static"),
|
||||
LOG_LEVEL=(str, "DEBUG"),
|
||||
LOG_FORMAT=(str, "default"),
|
||||
APP_DATA=(Path, PROJECT_ROOT / "data"),
|
||||
DATABASE_URL=str,
|
||||
DATABASE_URL=(str, "sqlite:////app/db/db.sqlite3"),
|
||||
REGISTRATION_OPEN=(bool, True),
|
||||
MAILGUN_API_KEY=(str, ""),
|
||||
MAILGUN_SENDER_DOMAIN=(str, ""),
|
||||
MAILGUN_SENDER_ADDRESS=(str, ""),
|
||||
CSRF_TRUSTED_ORIGINS=(list, ["http://localhost:8000"]),
|
||||
)
|
||||
|
||||
env_file = os.getenv("ENV_FILE", None)
|
||||
|
@ -55,7 +60,9 @@ EXTERNAL_APPS = [
|
|||
"django_cleanup.apps.CleanupConfig", # should be last: https://pypi.org/project/django-cleanup/
|
||||
]
|
||||
if DEBUG_TOOLBAR:
|
||||
EXTERNAL_APPS.append("debug_toolbar")
|
||||
EXTERNAL_APPS.insert(-2, "debug_toolbar")
|
||||
if DEBUG:
|
||||
EXTERNAL_APPS.insert(-2, "django_browser_reload")
|
||||
|
||||
CUSTOM_APPS = [
|
||||
"whitenoise.runserver_nostatic", # should be first
|
||||
|
@ -77,6 +84,8 @@ MIDDLEWARE = [
|
|||
]
|
||||
if DEBUG_TOOLBAR:
|
||||
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
|
||||
if DEBUG:
|
||||
MIDDLEWARE.append("django_browser_reload.middleware.BrowserReloadMiddleware")
|
||||
|
||||
ROOT_URLCONF = "{{cookiecutter.project_slug}}.urls"
|
||||
|
||||
|
@ -204,3 +213,40 @@ LOGIN_URL = "/admin/login"
|
|||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
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 = env("MAILGUN_SENDER_ADDRESS")
|
||||
SERVER_EMAIL = env("MAILGUN_SENDER_ADDRESS")
|
||||
|
||||
if DEBUG:
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
APP = {
|
||||
"build": {
|
||||
"date": "latest-date",
|
||||
"commit": "latest-commit",
|
||||
"describe": "latest-describe",
|
||||
}
|
||||
}
|
||||
try:
|
||||
with open("/app/git/build-date") as f:
|
||||
APP["build"]["date"] = f.read().strip()
|
||||
except Exception: # noqa: S110
|
||||
pass
|
||||
try:
|
||||
with open("/app/git/git-commit") as f:
|
||||
APP["build"]["commit"] = f.read().strip()
|
||||
except Exception: # noqa: S110
|
||||
pass
|
||||
try:
|
||||
with open("/app/git/git-describe") as f:
|
||||
APP["build"]["describe"] = f.read().strip()
|
||||
except Exception: # noqa: S110
|
||||
pass
|
||||
|
|
|
@ -18,11 +18,20 @@ from django.conf.urls.static import static
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth import logout
|
||||
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
|
||||
|
||||
urlpatterns = [
|
||||
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("", hello_world, name="hello_world"),
|
||||
]
|
||||
|
@ -31,3 +40,6 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|||
|
||||
if settings.DEBUG_TOOLBAR:
|
||||
urlpatterns.insert(0, path("__debug__/", include("debug_toolbar.urls")))
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns.insert(0, path("__reload__/", include("django_browser_reload.urls")))
|
||||
|
|
Loading…
Reference in a new issue