mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 20:01:51 +02:00
set up basic authentication
This commit is contained in:
parent
d0279578a5
commit
ca026a4617
13 changed files with 100 additions and 1 deletions
0
la_chariotte/accounts/__init__.py
Normal file
0
la_chariotte/accounts/__init__.py
Normal file
6
la_chariotte/accounts/apps.py
Normal file
6
la_chariotte/accounts/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class AccountsConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "la_chariotte.accounts"
|
0
la_chariotte/accounts/migrations/__init__.py
Normal file
0
la_chariotte/accounts/migrations/__init__.py
Normal file
3
la_chariotte/accounts/models.py
Normal file
3
la_chariotte/accounts/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
13
la_chariotte/accounts/templates/registration/login.html
Normal file
13
la_chariotte/accounts/templates/registration/login.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Connexion{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Connexion</h2>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Se connecter</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
13
la_chariotte/accounts/templates/registration/signup.html
Normal file
13
la_chariotte/accounts/templates/registration/signup.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Créer un compte{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Créer un compte</h2>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Valider</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
8
la_chariotte/accounts/urls.py
Normal file
8
la_chariotte/accounts/urls.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = "accounts"
|
||||||
|
urlpatterns = [
|
||||||
|
path("inscription/", views.SignUpView.as_view(), name="signup"),
|
||||||
|
]
|
9
la_chariotte/accounts/views.py
Normal file
9
la_chariotte/accounts/views.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.views import generic
|
||||||
|
|
||||||
|
|
||||||
|
class SignUpView(generic.CreateView):
|
||||||
|
form_class = UserCreationForm
|
||||||
|
success_url = reverse_lazy("login")
|
||||||
|
template_name = "registration/signup.html"
|
|
@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
"la_chariotte.order",
|
"la_chariotte.order",
|
||||||
|
"la_chariotte.accounts",
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
|
@ -52,10 +53,13 @@ MIDDLEWARE = [
|
||||||
|
|
||||||
ROOT_URLCONF = "la_chariotte.urls"
|
ROOT_URLCONF = "la_chariotte.urls"
|
||||||
|
|
||||||
|
LOGIN_REDIRECT_URL = "home"
|
||||||
|
LOGOUT_REDIRECT_URL = "home"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
"DIRS": [],
|
"DIRS": [BASE_DIR / "la_chariotte" / "templates"],
|
||||||
"APP_DIRS": True,
|
"APP_DIRS": True,
|
||||||
"OPTIONS": {
|
"OPTIONS": {
|
||||||
"context_processors": [
|
"context_processors": [
|
||||||
|
|
13
la_chariotte/templates/base.html
Normal file
13
la_chariotte/templates/base.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>{% block title %}{% endblock %} - La Chariotte</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
19
la_chariotte/templates/home.html
Normal file
19
la_chariotte/templates/home.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Accueil{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
Hi {{ user.username }}!
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'order:index' %}">Mes commandes groupées</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'logout' %}">Se déconnecter</a>
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p>You are not logged in</p>
|
||||||
|
<a href="{% url 'login' %}">Se connecter</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -15,8 +15,12 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("commande/", include("la_chariotte.order.urls")),
|
path("commande/", include("la_chariotte.order.urls")),
|
||||||
|
path("comptes/", include("la_chariotte.accounts.urls")),
|
||||||
|
path("comptes/", include("django.contrib.auth.urls")),
|
||||||
|
path("", TemplateView.as_view(template_name="home.html"), name="home"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -33,3 +33,10 @@ Si il y a des erreurs BLACK, on peut lancer black pour linter le code :
|
||||||
```bash
|
```bash
|
||||||
black .
|
black .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Architecture de l'application
|
||||||
|
|
||||||
|
Les différentes applications Django créées sont :
|
||||||
|
|
||||||
|
- Order, pour gérer tout ce qui tourne autour des commandes
|
||||||
|
- Accounts, pour gérer la création de comptes. Pour la connexion, la déconnexion et le changement de mot de passe, on utilise l'application auth intégrée à Django.
|
||||||
|
|
Loading…
Reference in a new issue