merged login view with website Index, wasted time on small details
This commit is contained in:
@@ -114,6 +114,7 @@ class WebsiteTemplateMixin(TemplateResponseMixin):
|
||||
context['stylesheets'] = self.Configuration.stylesheets
|
||||
context['apps'] = self.Configuration.apps
|
||||
context['active_app'] = self.active_app
|
||||
context['user_group'] = self.request.user.groups.first()
|
||||
#Webpage
|
||||
context['content_template'] = self.get_content_template()
|
||||
context['app_menu'] = self.get_menu()
|
||||
|
||||
@@ -14,14 +14,17 @@
|
||||
|
||||
.navbar-fixed-side .navbar-nav>li>a {
|
||||
border-bottom: none;
|
||||
font-variant: small-caps;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
|
||||
.app-menu {
|
||||
background-color: #121212;
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
||||
@media (max-width:768px){
|
||||
#menu { border: none; }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ page_title }}{% endblock %}
|
||||
{% block page_header %}{{ page_header }} <small>{{ page_header_small }}</small>{% endblock %}
|
||||
{% block page_header %}<span style="color:#980300;">{{ page_header }}</span> <small>{{ page_header_small }}</small>{% endblock %}
|
||||
|
||||
|
||||
{% block content %}{% include content_template %}{% endblock %}
|
||||
|
||||
{% block panels %}
|
||||
{% if panels %}<div class="panel-group">{% for panel in panels %}{% include panel %}{% endfor %}</div>
|
||||
{% else %}{{ block.super }}{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="{% url 'index' %}">La Maraude ALSA</a>
|
||||
</div>{% if user.is_authenticated %}
|
||||
</div>
|
||||
<div class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">{% for app in apps %}
|
||||
<li {% if app == active_app %} class="active" {%endif%}>
|
||||
@@ -21,25 +21,28 @@
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li class="dropdown">
|
||||
<a id="UserMenu" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
{% bootstrap_icon "user" %} {{user}} <span class="caret"></span></a>
|
||||
<strong style="color:#fff;">{% bootstrap_icon "user" %} {{user}} </strong>· {{ user_group }}<span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" aria-labelledby="UserMenu">
|
||||
{% if user.is_superuser %}<li><a href="/admin/">Administration {% bootstrap_icon "new-window" %} </a></li>{% endif %}
|
||||
{% if user.is_authenticated %}
|
||||
{% if user.is_superuser %}<li><a href="/admin/">Administration {% bootstrap_icon "new-window" %} </a></li>{% endif %}
|
||||
<li><a href="{% url 'logout' %}">Déconnecter {% bootstrap_icon "log-out" %}</a></li>
|
||||
{% else %}
|
||||
<li>
|
||||
<form class="navbar-form navbar-left" method="post" action="">{% csrf_token %}
|
||||
{% if next %}
|
||||
<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 />
|
||||
{% endif %}
|
||||
<div class="form-group form-horizontal">
|
||||
{% bootstrap_form form layout="horizontal" show_label=False %}
|
||||
</div>
|
||||
<div class="text-center"><button class="btn btn-primary navbar-button" type="submit">Connexion</button></div>
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="collapse navbar-collapse">
|
||||
<div class="text-center navbar-text"><h4 style="color:#fff;">Connexion</h4></div>
|
||||
<form class="navbar-form navbar-left" method="post" action="{% url 'login' %}">
|
||||
<div class="form-group text-center">{% csrf_token %}
|
||||
<input autofocus="" class="form-control" id="id_username" maxlength="254" name="username" placeholder="Nom d'utilisateur" title="" type="text" required />
|
||||
<input class="form-control" id="id_password" name="password" placeholder="Mot de passe" title="" type="password" required />
|
||||
<input type="hidden" name="next" value="{{ next|default:'/maraudes/' }}" /><br />
|
||||
<button class="btn btn-default" type="submit">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -8,15 +8,14 @@ from suivi import urls as suivi_urls
|
||||
from sujets import urls as sujets_urls
|
||||
|
||||
urlpatterns = [
|
||||
# Authentification
|
||||
url('^$', Index.as_view(), name="index"),
|
||||
url(r'^logout/$', auth_views.logout, {
|
||||
'template_name': 'logout.html',
|
||||
'next_page': 'index',
|
||||
}, name="logout"),
|
||||
# Applications
|
||||
url(r'^maraudes/', include(maraudes_urls, namespace="maraudes")),
|
||||
url(r'^suivi/', include(suivi_urls, namespace="suivi")),
|
||||
url(r'^sujets/', include(sujets_urls, namespace="sujets")),
|
||||
# Authentification
|
||||
url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name="login"),
|
||||
url(r'^logout/$', auth_views.logout, {
|
||||
'template_name': 'logout.html',
|
||||
'next_page': 'login',
|
||||
}, name="logout"),
|
||||
]
|
||||
|
||||
@@ -1,21 +1,43 @@
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django import views
|
||||
from .mixins import WebsiteTemplateMixin
|
||||
|
||||
|
||||
from django.contrib.auth.views import login
|
||||
from django.http import HttpResponseRedirect
|
||||
class Index(WebsiteTemplateMixin, views.generic.TemplateView):
|
||||
|
||||
template_name = "main.html"
|
||||
app_menu = [] #TODO: fix this !
|
||||
login_response = None
|
||||
|
||||
class PageInfo:
|
||||
title = "La maraude ALSA"
|
||||
header = "La Maraude ALSA"
|
||||
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):
|
||||
# Should find best entry point according to user Group
|
||||
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):
|
||||
if not request.user.is_authenticated():
|
||||
return super().get(request, *args, **kwargs)
|
||||
else:
|
||||
return redirect('maraudes:index')
|
||||
if request.user.is_authenticated():
|
||||
return redirect(self._get_user_entry_point())
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user