updated login mechanism
This commit is contained in:
@@ -28,13 +28,23 @@
|
|||||||
<li><a href="{% url 'logout' %}">{% bootstrap_icon "log-out" %} Déconnecter</a></li>
|
<li><a href="{% url 'logout' %}">{% bootstrap_icon "log-out" %} Déconnecter</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li>
|
<li>
|
||||||
<form class="navbar-form navbar-left" method="post" action="">{% csrf_token %}
|
<form class="navbar-form navbar-left" method="post" action="/login/">{% csrf_token %}
|
||||||
{% if next %}
|
{% if next %}
|
||||||
<p class="well-sm text-center"><strong style="color:#980300;">Vous devez vous connecter<br/> pour accéder à cette page.</strong></p>
|
<p class="well-sm text-center"><strong style="color:#980300;">Vous devez vous connecter<br/> pour accéder à cette page.</strong></p>
|
||||||
<input name="next" value="{{next}}" hidden />
|
<input name="next" value="{{next}}" hidden />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-group form-horizontal">
|
<div class="form-group form-horizontal">
|
||||||
{% bootstrap_form form layout="horizontal" show_label=False %}
|
<div class="form-group">
|
||||||
|
<label class="col-md-2 sr-only control-label" for="id_username">Username</label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input autofocus="" class="form-control" id="id_username" maxlength="254" name="username" placeholder="Username" title="" type="text" required />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-md-2 sr-only control-label" for="id_password">Password</label>
|
||||||
|
<div class="col-md-10"><input class="form-control" id="id_password" name="password" placeholder="Password" title="" type="password" required />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center"><button class="btn btn-primary navbar-button" type="submit">Connexion</button></div>
|
<div class="text-center"><button class="btn btn-primary navbar-button" type="submit">Connexion</button></div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ from django.conf.urls import include, url
|
|||||||
|
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
|
|
||||||
from .views import Index
|
from .views import Index, login_view
|
||||||
from maraudes import urls as maraudes_urls
|
from maraudes import urls as maraudes_urls
|
||||||
from suivi import urls as suivi_urls
|
from suivi import urls as suivi_urls
|
||||||
from sujets import urls as sujets_urls
|
from sujets import urls as sujets_urls
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Authentification
|
# Authentification
|
||||||
url('^$', Index.as_view(), name="index"),
|
url(r'^$', Index.as_view(), name="index"),
|
||||||
|
url(r'^login/$', login_view),
|
||||||
url(r'^logout/$', auth_views.logout, {
|
url(r'^logout/$', auth_views.logout, {
|
||||||
'template_name': 'logout.html',
|
'template_name': 'logout.html',
|
||||||
'next_page': 'index',
|
'next_page': 'index',
|
||||||
|
|||||||
@@ -4,40 +4,32 @@ from django import views
|
|||||||
from .mixins import WebsiteTemplateMixin
|
from .mixins import WebsiteTemplateMixin
|
||||||
|
|
||||||
from django.contrib.auth.views import login
|
from django.contrib.auth.views import login
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
||||||
|
|
||||||
class Index(WebsiteTemplateMixin, views.generic.TemplateView):
|
class Index(WebsiteTemplateMixin, views.generic.TemplateView):
|
||||||
|
|
||||||
template_name = "main.html"
|
template_name = "main.html"
|
||||||
app_menu = None
|
app_menu = None
|
||||||
login_response = None
|
|
||||||
|
|
||||||
class PageInfo:
|
class PageInfo:
|
||||||
title = "La maraude ALSA"
|
title = "La maraude ALSA"
|
||||||
header = "La Maraude ALSA"
|
header = "La Maraude ALSA"
|
||||||
header_small = "accueil"
|
header_small = "accueil"
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
self.user = request.user
|
|
||||||
self.login_response = login(request)
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def _get_user_entry_point(self):
|
def _get_user_entry_point(self):
|
||||||
# Should find best entry point according to user Group
|
# Should find best entry point according to user Group
|
||||||
return reverse('maraudes:index')
|
return reverse('maraudes:index')
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
if hasattr(self.login_response, 'url') and 'next' in self.request.POST:
|
|
||||||
return self.login_response
|
|
||||||
return self.get(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
return redirect(self._get_user_entry_point())
|
return redirect(self._get_user_entry_point())
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context.update(self.login_response.context_data)
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
|
def login_view(request):
|
||||||
|
if request.method == 'GET':
|
||||||
|
return HttpResponsePermanentRedirect('/')
|
||||||
|
elif request.method == 'POST':
|
||||||
|
response = login(request)
|
||||||
|
return HttpResponseRedirect('/')
|
||||||
|
|||||||
Reference in New Issue
Block a user