Implement login
This commit is contained in:
parent
e8736e5303
commit
214bbf4299
3 changed files with 43 additions and 11 deletions
30
gym/templates/registration/login.html
Normal file
30
gym/templates/registration/login.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{% extends 'gym/base.html' %}
|
||||
{% load bootstrap4 %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% block title %}Connexion{% endblock %}</h1>
|
||||
|
||||
{% if next %}
|
||||
{% if user.is_authenticated %}
|
||||
<p>Votre compte n'a pas accès à cette page. Pour continuer,
|
||||
merci de vous connecter avec un compte disposant
|
||||
des autorisations nécessaires.</p>
|
||||
{% else %}
|
||||
<p>Merci de vous connecter pour accéder à cette page.</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{% url 'login' %}">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-primary">Connexion</button>
|
||||
{% endbuttons %}
|
||||
|
||||
<input type="hidden" name="next" value="{{ next }}"/>
|
||||
</form>
|
||||
|
||||
{# Assumes you setup the password_reset view in your URLconf #}
|
||||
{# <p><a href="{% url 'password_reset' %}">Mot de passe oublié ?</a></p>#}
|
||||
|
||||
{% endblock %}
|
23
gym/views.py
23
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'
|
||||
|
|
|
@ -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')),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue