set up basic authentication

This commit is contained in:
Laetitia Getti 2023-04-12 16:18:13 +02:00
parent d0279578a5
commit ca026a4617
13 changed files with 100 additions and 1 deletions

View file

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "la_chariotte.accounts"

View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View 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 %}

View 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 %}

View 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"),
]

View 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"

View file

@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
"la_chariotte.order",
"la_chariotte.accounts",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
@ -52,10 +53,13 @@ MIDDLEWARE = [
ROOT_URLCONF = "la_chariotte.urls"
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "la_chariotte" / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [

View 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>

View 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 %}

View file

@ -15,8 +15,12 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from django.views.generic.base import TemplateView
urlpatterns = [
path("admin/", admin.site.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"),
]

View file

@ -33,3 +33,10 @@ Si il y a des erreurs BLACK, on peut lancer black pour linter le code :
```bash
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.