From 214bbf4299531115f9bb14fbacecbc2c22b6bc6e Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 4 Mar 2018 18:45:31 +0100 Subject: [PATCH] Implement login --- gym/templates/registration/login.html | 30 +++++++++++++++++++++++++++ gym/views.py | 23 ++++++++++---------- workout/urls.py | 1 + 3 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 gym/templates/registration/login.html diff --git a/gym/templates/registration/login.html b/gym/templates/registration/login.html new file mode 100644 index 0000000..eae0b36 --- /dev/null +++ b/gym/templates/registration/login.html @@ -0,0 +1,30 @@ +{% extends 'gym/base.html' %} +{% load bootstrap4 %} + +{% block content %} +

{% block title %}Connexion{% endblock %}

+ + {% if next %} + {% if user.is_authenticated %} +

Votre compte n'a pas accès à cette page. Pour continuer, + merci de vous connecter avec un compte disposant + des autorisations nécessaires.

+ {% else %} +

Merci de vous connecter pour accéder à cette page.

+ {% endif %} + {% endif %} + +
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} + + +
+ + {# Assumes you setup the password_reset view in your URLconf #} +{#

Mot de passe oublié ?

#} + +{% endblock %} \ No newline at end of file diff --git a/gym/views.py b/gym/views.py index 9936b3e..f315820 100644 --- a/gym/views.py +++ b/gym/views.py @@ -1,5 +1,6 @@ import datetime +from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import get_object_or_404 from django.urls import reverse from django.views import generic @@ -7,7 +8,7 @@ from django.views import generic from gym.models import Room, Equipment, Setting, Session, Round, TheoreticalMax -class RoomListView(generic.ListView): +class RoomListView(LoginRequiredMixin, generic.ListView): queryset = Room.objects.all().order_by('name') context_object_name = 'rooms' template_name = 'gym/rooms.html' @@ -19,7 +20,7 @@ class RoomListView(generic.ListView): return super().dispatch(request, *args, **kwargs) -class RoomDetailView(generic.DetailView): +class RoomDetailView(LoginRequiredMixin, generic.DetailView): model = Room context_object_name = 'room' template_name = 'gym/room.html' @@ -36,7 +37,7 @@ class RoomDetailView(generic.DetailView): return context -class EquipmentDetailView(generic.DetailView): +class EquipmentDetailView(LoginRequiredMixin, generic.DetailView): model = Equipment context_object_name = 'equipment' template_name = 'gym/equipment.html' @@ -56,7 +57,7 @@ class EquipmentDetailView(generic.DetailView): return context -class EquipmentCreateView(generic.CreateView): +class EquipmentCreateView(LoginRequiredMixin, generic.CreateView): model = Equipment fields = ['room', 'name'] template_name = 'gym/equipment_edit.html' @@ -84,7 +85,7 @@ class EquipmentCreateView(generic.CreateView): return initial -class SettingCreateView(generic.CreateView): +class SettingCreateView(LoginRequiredMixin, generic.CreateView): model = Setting fields = ['equipment', 'name', 'value'] template_name = 'gym/setting_edit.html' @@ -113,7 +114,7 @@ class SettingCreateView(generic.CreateView): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) -class SettingUpdateView(generic.UpdateView): +class SettingUpdateView(LoginRequiredMixin, generic.UpdateView): model = Setting fields = ['equipment', 'name', 'value'] template_name = 'gym/setting_edit.html' @@ -129,7 +130,7 @@ class SettingUpdateView(generic.UpdateView): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) -class SettingDeleteView(generic.DeleteView): +class SettingDeleteView(LoginRequiredMixin, generic.DeleteView): model = Setting template_name = 'gym/setting_confirm_delete.html' context_object_name = 'setting' @@ -138,7 +139,7 @@ class SettingDeleteView(generic.DeleteView): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) -class TheoreticalMaxCreateView(generic.CreateView): +class TheoreticalMaxCreateView(LoginRequiredMixin, generic.CreateView): model = TheoreticalMax fields = ['equipment', 'date', 'value'] template_name = 'gym/theoretical_max_edit.html' @@ -168,7 +169,7 @@ class TheoreticalMaxCreateView(generic.CreateView): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) -class SessionCreateView(generic.CreateView): +class SessionCreateView(LoginRequiredMixin, generic.CreateView): model = Session fields = ['room', 'start'] template_name = 'gym/session_edit.html' @@ -197,7 +198,7 @@ class SessionCreateView(generic.CreateView): return initial -class SessionDetailView(generic.DetailView): +class SessionDetailView(LoginRequiredMixin, generic.DetailView): model = Session context_object_name = 'session' template_name = 'gym/session_detail.html' @@ -207,7 +208,7 @@ class SessionDetailView(generic.DetailView): return super().get(request, *args, **kwargs) -class RoundCreateView(generic.CreateView): +class RoundCreateView(LoginRequiredMixin, generic.CreateView): model = Round fields = ['equipment', 'session', 'theoretical_max_percentage', 'chosen_weight', 'repetition_number', 'notes'] template_name = 'gym/round_edit.html' diff --git a/workout/urls.py b/workout/urls.py index 5570311..d304600 100644 --- a/workout/urls.py +++ b/workout/urls.py @@ -19,5 +19,6 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('accounts/', include('django.contrib.auth.urls')), url(r'', include('gym.urls')), ]