diff --git a/la_chariotte/accounts/__init__.py b/la_chariotte/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/la_chariotte/accounts/apps.py b/la_chariotte/accounts/apps.py new file mode 100644 index 0000000..299b83e --- /dev/null +++ b/la_chariotte/accounts/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "la_chariotte.accounts" diff --git a/la_chariotte/accounts/migrations/__init__.py b/la_chariotte/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/la_chariotte/accounts/models.py b/la_chariotte/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/la_chariotte/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/la_chariotte/accounts/templates/registration/login.html b/la_chariotte/accounts/templates/registration/login.html new file mode 100644 index 0000000..b4f1f96 --- /dev/null +++ b/la_chariotte/accounts/templates/registration/login.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block title %}Connexion{% endblock %} + +{% block content %} +

Connexion

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} \ No newline at end of file diff --git a/la_chariotte/accounts/templates/registration/signup.html b/la_chariotte/accounts/templates/registration/signup.html new file mode 100644 index 0000000..c049920 --- /dev/null +++ b/la_chariotte/accounts/templates/registration/signup.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block title %}Créer un compte{% endblock %} + +{% block content %} +

Créer un compte

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} \ No newline at end of file diff --git a/la_chariotte/accounts/urls.py b/la_chariotte/accounts/urls.py new file mode 100644 index 0000000..7d7d715 --- /dev/null +++ b/la_chariotte/accounts/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +app_name = "accounts" +urlpatterns = [ + path("inscription/", views.SignUpView.as_view(), name="signup"), +] diff --git a/la_chariotte/accounts/views.py b/la_chariotte/accounts/views.py new file mode 100644 index 0000000..d9eb103 --- /dev/null +++ b/la_chariotte/accounts/views.py @@ -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" diff --git a/la_chariotte/settings.py b/la_chariotte/settings.py index 159b46b..9f9afff 100644 --- a/la_chariotte/settings.py +++ b/la_chariotte/settings.py @@ -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": [ diff --git a/la_chariotte/templates/base.html b/la_chariotte/templates/base.html new file mode 100644 index 0000000..25ceeb2 --- /dev/null +++ b/la_chariotte/templates/base.html @@ -0,0 +1,13 @@ + + + + + {% block title %}{% endblock %} - La Chariotte + + +
+ {% block content %} + {% endblock %} +
+ + \ No newline at end of file diff --git a/la_chariotte/templates/home.html b/la_chariotte/templates/home.html new file mode 100644 index 0000000..1a10e34 --- /dev/null +++ b/la_chariotte/templates/home.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} + +{% block title %}Accueil{% endblock %} + +{% block content %} +{% if user.is_authenticated %} + Hi {{ user.username }}! +

+ Mes commandes groupées +

+

+ Se déconnecter +

+{% else %} +

You are not logged in

+ Se connecter +{% endif %} +{% endblock %} + diff --git a/la_chariotte/urls.py b/la_chariotte/urls.py index cdef8bf..12ca068 100644 --- a/la_chariotte/urls.py +++ b/la_chariotte/urls.py @@ -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"), ] diff --git a/readMe.md b/readMe.md index b50408a..0362734 100644 --- a/readMe.md +++ b/readMe.md @@ -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.