Add user signup form and implement signup view; enhance message display in templates
This commit is contained in:
parent
6ab5748cbc
commit
700ab7ecca
8 changed files with 66 additions and 2 deletions
11
base/forms.py
Normal file
11
base/forms.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class UserSignupForm(UserCreationForm):
|
||||
email = forms.EmailField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["username", "email"]
|
|
@ -37,3 +37,30 @@ a.group {
|
|||
color: var(--pico-color-zinc-500);
|
||||
margin-left: .5em;
|
||||
}
|
||||
|
||||
article.message {
|
||||
&::before {
|
||||
margin-right: .5em;
|
||||
font-family: remixicon;
|
||||
}
|
||||
&.debug::before {
|
||||
content: "\eb06";
|
||||
color: var(--pico-color-zinc-500);
|
||||
}
|
||||
&.info::before {
|
||||
content: "\ee58";
|
||||
color: var(--pico-color-indigo-600);
|
||||
}
|
||||
&.success::before {
|
||||
content: "\eb80";
|
||||
color: var(--pico-color-green-500);
|
||||
}
|
||||
&.warning::before {
|
||||
content: "\eca0";
|
||||
color: var(--pico-color-amber-200);
|
||||
}
|
||||
&.error::before {
|
||||
content: "\eca0";
|
||||
color: var(--pico-color-red-500);
|
||||
}
|
||||
}
|
||||
|
|
6
base/templates/auth/user_form.html
Normal file
6
base/templates/auth/user_form.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>Créer un compte</h1>
|
||||
{% form form %}
|
||||
{% endblock content %}
|
|
@ -57,6 +57,7 @@
|
|||
</div>
|
||||
</header>
|
||||
<main class="container">
|
||||
{% for message in messages %}<article class="message {{ message.tags }}">{{ message }}</article>{% endfor %}
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
</main>
|
||||
|
|
|
@ -2,5 +2,8 @@
|
|||
{% load form %}
|
||||
{% block content %}
|
||||
<h1>Connexion</h1>
|
||||
<p>
|
||||
<a href="{% url "signup" %}">Créer un compte</a>
|
||||
</p>
|
||||
{% form form submit="Se connecter" %}
|
||||
{% endblock content %}
|
||||
|
|
|
@ -4,5 +4,6 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("", views.HomePageView.as_view(), name="index"),
|
||||
path("accounts/signup/", views.SignupView.as_view(), name="signup"),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
]
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView
|
||||
|
||||
from . import forms
|
||||
|
||||
|
||||
class HomePageView(TemplateView):
|
||||
template_name = "index.html"
|
||||
|
||||
|
||||
class SignupView(SuccessMessageMixin, CreateView):
|
||||
model = User
|
||||
form_class = forms.UserSignupForm
|
||||
success_url = "/"
|
||||
success_message = "Le compte %(username)s a été créé avec succès."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue