Implementation de sso
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -40,12 +40,9 @@ INSTALLED_APPS = [
|
||||
'gestion_employe',
|
||||
'gestion_conge',
|
||||
'gestion_projet',
|
||||
'gestion_salle',
|
||||
'simple_sso.sso_server'
|
||||
'gestion_salle'
|
||||
]
|
||||
|
||||
LOGIN_URL = 'login'
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
@@ -150,6 +147,15 @@ MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# Connexion sso
|
||||
# LOGIN_URL = '/client/'
|
||||
LOGIN_URL = 'simple-sso-login'
|
||||
|
||||
SSO_PRIVATE_KEY = 'wV3nf1YXeZpepf8iJAdWcfJOS4BVXYlIKsKES2RheuJLu5ycgm0ZK3zgdw9ODjdo' # Designe la clé privée
|
||||
SSO_PUBLIC_KEY = 'E8vV810D8HSmhUwl6abuZALhO5fmUdjjd3wAVCFZyyDX7SsSeAf9XwVyKZ5brilt' # Designe la clé publique
|
||||
SSO_SERVER = 'http://localhost:8000/server/'
|
||||
SSO_LOGOUT_URL = 'http://localhost:8000/deconnexion'
|
||||
|
||||
# Configuration de l'email
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'ssl0.ovh.net'
|
||||
@@ -158,4 +164,4 @@ EMAIL_USE_SSL = True
|
||||
EMAIL_USE_TLS = False
|
||||
EMAIL_HOST_USER = 'support.it@cerfig.org'
|
||||
EMAIL_HOST_PASSWORD = 'Cerfig2025'
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
33
SIRH/sso.py
Normal file
33
SIRH/sso.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# SGL/sso.py
|
||||
from gestion_employe.models import Employe, Departement
|
||||
from simple_sso.sso_client.client import Client
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
class SIRHClient(Client):
|
||||
def build_user(self, user_data):
|
||||
"""Crée le User et son Profile avec les infos reçues du serveur."""
|
||||
user_data_copy = user_data.copy()
|
||||
user_data.pop("departement")
|
||||
user_data.pop("chef_departement")
|
||||
user_data.pop("groups")
|
||||
|
||||
user = super().build_user(user_data)
|
||||
departement = Departement.objects.get_or_create(
|
||||
nom=user_data_copy.get("departement", ""))[0]
|
||||
|
||||
Employe.objects.update_or_create(
|
||||
user = user,
|
||||
defaults = {
|
||||
"departement": departement,
|
||||
"chef": user_data_copy.get("chef_departement", ""),
|
||||
}
|
||||
)
|
||||
|
||||
for group_name in user_data_copy.get("groups", []):
|
||||
group, _ = Group.objects.get_or_create(name=group_name)
|
||||
user.groups.add(group)
|
||||
|
||||
return user
|
||||
@@ -15,8 +15,9 @@
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<div class="row flex-nowrap">
|
||||
{% include 'parts/menu_application.html' %}
|
||||
{% include 'parts/menu_principal.html' %}
|
||||
<div class="col-9 p-4">
|
||||
<div class="col p-4">
|
||||
{% block 'contenu' %} {% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -24,15 +24,16 @@
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
<div class="mb-3">
|
||||
<label for="mail">Votre adresse email :</label>
|
||||
<input type="text" name="mail" class="form-control" placeholder="Entrez votre e-mail" required>
|
||||
<label for="mail">Votre adresse email :</label>
|
||||
<input type="text" name="mail" class="form-control" placeholder="Entrez votre e-mail" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="mot_de_passe">Mot de passe</label>
|
||||
<input type="password" name="mot_de_passe" class="form-control" placeholder="Entrez votre mot de passe" required>
|
||||
<i class="bi bi-eye toggle-password" onclick="togglePassword()"
|
||||
style="position:absolute; right:10px; top:38px; cursor:pointer;"></i>
|
||||
<label for="mot_de_passe">Mot de passe</label>
|
||||
<input type="password" name="mot_de_passe" class="form-control" placeholder="Entrez votre mot de passe" required>
|
||||
<i class="bi bi-eye toggle-password" onclick="togglePassword()"
|
||||
style="position:absolute; right:10px; top:38px; cursor:pointer;"></i>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Se connecter</button>
|
||||
</form>
|
||||
|
||||
8
SIRH/templates/SIRH/parts/menu_application.html
Normal file
8
SIRH/templates/SIRH/parts/menu_application.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="col-1 bg-danger border d-flex flex-column vh-100 pt-5 sticky-top">
|
||||
<a href="http://localhost:8002/" class="text-white text-center fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<i class="bi bi-people-fill fs-1 d-block"></i>SIRH
|
||||
</a>
|
||||
<a href="http://localhost:8001/" class="text-white text-center fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<i class="bi bi-building-gear fs-1 d-block"></i> SGL
|
||||
</a>
|
||||
</div>
|
||||
@@ -13,35 +13,36 @@
|
||||
<i class="bi bi-person-circle text-white" style="font-size:60px;"></i>
|
||||
{% endif %}
|
||||
<div class="text-white mt-2 fw-bold fs-5">
|
||||
{{ user.username }}
|
||||
{{ user.first_name }} {{ user.last_name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{% url 'gestion_employe:mon-profil' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_employe:mon-profil' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-person-circle"></i> Mon profil
|
||||
</a>
|
||||
{% if user|has_group:"ressource_humaine" or user|has_group:"direction" %}
|
||||
<a href="{% url 'gestion_employe:index' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_employe:index' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-speedometer2"></i> Tableau de bord
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if user|has_group:"ressource_humaine" or user|has_group:"direction" %}
|
||||
<a href="{% url 'gestion_projet:index' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_projet:index' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-folder"></i> Gestion des Projets
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'gestion_conges:conge' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_conges:conge' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-airplane"></i> Gestion des congés
|
||||
</a>
|
||||
{% if user|is_chef_projet %}
|
||||
<a href="{% url 'gestion_projet:activites-projet' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_projet:activites-projet' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-list-task"></i> Suivi des Activités
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'gestion_salle:reservation-salle' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
<a href="{% url 'gestion_salle:reservation-salle' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-calendar-check"></i> Réservation
|
||||
</a>
|
||||
<a href="{% url 'deconnexion' %}" class="text-white fw-bold text-decoration-none mb-4" style="font-size:1.4em">
|
||||
{% comment %} {% url 'deconnexion' %} {% endcomment %}
|
||||
<a href="" class="text-white fw-bold text-decoration-none mb-4" style="font-size: 1.2em;">
|
||||
<i class="bi bi-box-arrow-right"></i> Déconnexion
|
||||
</a>
|
||||
</div>
|
||||
47
SIRH/urls.py
47
SIRH/urls.py
@@ -16,32 +16,29 @@ Including another URLconf
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.conf.urls.static import static
|
||||
# from django.conf.urls.static import static
|
||||
from django.conf import settings
|
||||
# from simple_sso.sso_server.server import Server
|
||||
|
||||
from . import views
|
||||
from .sso import SIRHClient
|
||||
|
||||
# server_sso = Server()
|
||||
client_sirh = SIRHClient(
|
||||
settings.SSO_SERVER,
|
||||
settings.SSO_PUBLIC_KEY,
|
||||
settings.SSO_PRIVATE_KEY
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = [
|
||||
# path('login/',
|
||||
# views.login_view,
|
||||
# name='login'
|
||||
# ),
|
||||
# path(
|
||||
# 'deconnexion/',
|
||||
# views.deconnexion_view,
|
||||
# name='deconnexion'
|
||||
# ),
|
||||
path(
|
||||
'',
|
||||
views.login_view,
|
||||
name='index'
|
||||
),
|
||||
|
||||
path('login/',
|
||||
views.login_view,
|
||||
name='login'
|
||||
),
|
||||
path(
|
||||
'deconnexion/',
|
||||
views.deconnexion_view,
|
||||
name='deconnexion'
|
||||
),
|
||||
path(
|
||||
'employé/',
|
||||
include("gestion_employe.urls")
|
||||
),
|
||||
path(
|
||||
@@ -59,9 +56,7 @@ urlpatterns = [
|
||||
path(
|
||||
'admin/',
|
||||
admin.site.urls
|
||||
),
|
||||
# path(
|
||||
# 'sso',
|
||||
# include(server_sso.get_urls())
|
||||
# )
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
),
|
||||
path("client/", include(client_sirh.get_urls())),
|
||||
]
|
||||
# + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
@@ -1,37 +0,0 @@
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
|
||||
def login_view(request):
|
||||
"""
|
||||
Gère la connexion des utilisateurs avec redirection selon le rôle et
|
||||
vérification de l'acceptation de la politique d'utilisation.
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
email = request.POST.get('mail')
|
||||
password = request.POST.get('mot_de_passe')
|
||||
|
||||
if not (email and password):
|
||||
messages.error(request, "Veuillez remplir tous les champs.")
|
||||
return render(request, 'login.html')
|
||||
|
||||
user = authenticate(request, username=email, password=password)
|
||||
|
||||
if user is None:
|
||||
messages.error(request, "Nom d’utilisateur ou mot de passe incorrect.")
|
||||
return render(request, 'login.html')
|
||||
|
||||
if not user.is_active:
|
||||
messages.error(request, "Compte inactif. Contactez l'administrateur.")
|
||||
return render(request, 'login.html')
|
||||
|
||||
login(request, user)
|
||||
|
||||
return redirect("gestion_conges:conge")
|
||||
|
||||
return render(request, 'login.html')
|
||||
|
||||
def deconnexion_view(request):
|
||||
"""Gère la déconnexion de l'utilisateur."""
|
||||
logout(request)
|
||||
return redirect('login')
|
||||
Reference in New Issue
Block a user