Merge pull request #8 from winkaeter/4-mettre-en-place-des-authentifications

Gestion d'authentification terminée
This commit is contained in:
winkaeter 2026-03-27 17:01:18 +01:00 committed by GitHub
commit 1e409c4832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 453 additions and 27 deletions

View file

@ -61,11 +61,19 @@
<Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> <Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="controller\FrmAuthController.cs" />
<Compile Include="manager\ApiRest.cs" /> <Compile Include="manager\ApiRest.cs" />
<Compile Include="controller\FrmMediatekController.cs" /> <Compile Include="controller\FrmMediatekController.cs" />
<Compile Include="dal\Access.cs" /> <Compile Include="dal\Access.cs" />
<Compile Include="model\Abonnement.cs" /> <Compile Include="model\Abonnement.cs" />
<Compile Include="model\CommandeDocument.cs" /> <Compile Include="model\CommandeDocument.cs" />
<Compile Include="model\Utilisateur.cs" />
<Compile Include="view\FrmAuth.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="view\FrmAuth.Designer.cs">
<DependentUpon>FrmAuth.cs</DependentUpon>
</Compile>
<Compile Include="view\FrmMediatek.cs"> <Compile Include="view\FrmMediatek.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -94,6 +102,9 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<EmbeddedResource Include="view\FrmAuth.resx">
<DependentUpon>FrmAuth.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="view\FrmMediatek.resx"> <EmbeddedResource Include="view\FrmMediatek.resx">
<DependentUpon>FrmMediatek.cs</DependentUpon> <DependentUpon>FrmMediatek.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View file

@ -14,7 +14,15 @@ namespace MediaTekDocuments
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMediatek());
//Application.Run(new FrmAuth());
FrmAuth auth = new FrmAuth();
if (auth.ShowDialog() == DialogResult.OK)
{
Utilisateur user = auth.user;
Application.Run(new FrmMediatek(user));
}
} }
} }
} }

View file

@ -0,0 +1,22 @@
using System.Collections.Generic;
using MediaTekDocuments.model;
using MediaTekDocuments.dal;
using System;
namespace MediaTekDocuments.controller
{
class FrmAuthController
{
private readonly Access access;
public FrmAuthController()
{
access = Access.GetInstance();
}
public Utilisateur GetConnection(string login, string pwd)
{
return access.GetConnection(login, pwd);
}
}
}

View file

@ -360,5 +360,23 @@ namespace MediaTekDocuments.dal
} }
catch { return false; } catch { return false; }
} }
public Utilisateur GetConnection(string login, string pwd)
{
Dictionary<string, string> loginInfo = new Dictionary<string, string>
{
{ "identifiant", login },
{ "motDePasse", pwd }
};
string jsonLogin = JsonConvert.SerializeObject(loginInfo);
List<Utilisateur> lesUtilisateurs = TraitementRecup<Utilisateur>(GET, "utilisateur/" + jsonLogin, null);
if (lesUtilisateurs != null && lesUtilisateurs.Count > 0)
{
return lesUtilisateurs[0];
}
return null;
}
} }
} }

View file

@ -0,0 +1,19 @@
public class Utilisateur
{
public string Id { get; set; }
public string Identifiant { get; set; }
public string Nom { get; set; }
public string Prenom { get; set; }
public int IdService { get; set; }
public string LibelleService { get; set; }
public Utilisateur(string id, string identifiant, string nom, string prenom, int idService, string libelleService)
{
this.Id = id;
this.Identifiant = identifiant;
this.Nom = nom;
this.Prenom = prenom;
this.IdService = idService;
this.LibelleService = libelleService;
}
}

136
MediaTekDocuments/view/FrmAuth.Designer.cs generated Normal file
View file

@ -0,0 +1,136 @@

namespace MediaTekDocuments.view
{
partial class FrmAuth
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.grpAuthInfos = new System.Windows.Forms.GroupBox();
this.btnLogin = new System.Windows.Forms.Button();
this.txtPassword = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtIdentifiant = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.lblErreur = new System.Windows.Forms.Label();
this.grpAuthInfos.SuspendLayout();
this.SuspendLayout();
//
// grpAuthInfos
//
this.grpAuthInfos.Controls.Add(this.lblErreur);
this.grpAuthInfos.Controls.Add(this.btnLogin);
this.grpAuthInfos.Controls.Add(this.txtPassword);
this.grpAuthInfos.Controls.Add(this.label2);
this.grpAuthInfos.Controls.Add(this.txtIdentifiant);
this.grpAuthInfos.Controls.Add(this.label1);
this.grpAuthInfos.Location = new System.Drawing.Point(13, 13);
this.grpAuthInfos.Name = "grpAuthInfos";
this.grpAuthInfos.Size = new System.Drawing.Size(200, 118);
this.grpAuthInfos.TabIndex = 0;
this.grpAuthInfos.TabStop = false;
this.grpAuthInfos.Text = "Se connecter";
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(6, 89);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(75, 23);
this.btnLogin.TabIndex = 4;
this.btnLogin.Text = "Connexion";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(95, 43);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(100, 20);
this.txtPassword.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(7, 46);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(82, 13);
this.label2.TabIndex = 2;
this.label2.Text = "mot de passe";
//
// txtIdentifiant
//
this.txtIdentifiant.Location = new System.Drawing.Point(76, 17);
this.txtIdentifiant.Name = "txtIdentifiant";
this.txtIdentifiant.Size = new System.Drawing.Size(100, 20);
this.txtIdentifiant.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(7, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 13);
this.label1.TabIndex = 0;
this.label1.Text = "identifiant";
//
// lblErreur
//
this.lblErreur.AutoSize = true;
this.lblErreur.Location = new System.Drawing.Point(7, 73);
this.lblErreur.Name = "lblErreur";
this.lblErreur.Size = new System.Drawing.Size(0, 13);
this.lblErreur.TabIndex = 5;
//
// FrmAuth
//
this.AcceptButton = this.btnLogin;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(227, 143);
this.Controls.Add(this.grpAuthInfos);
this.Name = "FrmAuth";
this.Text = "Connexion";
this.Load += new System.EventHandler(this.FrmAuth_Load);
this.grpAuthInfos.ResumeLayout(false);
this.grpAuthInfos.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox grpAuthInfos;
private System.Windows.Forms.TextBox txtIdentifiant;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Label lblErreur;
}
}

View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Windows.Forms;
using MediaTekDocuments.model;
using MediaTekDocuments.controller;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.IO;
namespace MediaTekDocuments.view
{
public partial class FrmAuth : Form
{
private readonly FrmAuthController controller;
public Utilisateur user { get; private set; }
public FrmAuth()
{
InitializeComponent();
this.controller = new FrmAuthController();
}
private void FrmAuth_Load(object sender, EventArgs e)
{
//
}
private void btnLogin_Click(object sender, EventArgs e)
{
string identifiant = txtIdentifiant.Text;
string password = txtPassword.Text;
Utilisateur user = controller.GetConnection(identifiant, password);
if(user == null)
{
txtIdentifiant.Text = "";
txtPassword.Text = "";
lblErreur.Text = "Identifiant ou mot de passe invalide.";
return;
}
if(user.LibelleService == "Culture")
{
MessageBox.Show("Vous n'êtes pas autorisé à accéder à cette application !", "Accès refusé", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.DialogResult = DialogResult.Abort;
this.Close();
}
this.user = user;
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -17,6 +17,7 @@ namespace MediaTekDocuments.view
{ {
#region Commun #region Commun
private readonly FrmMediatekController controller; private readonly FrmMediatekController controller;
private readonly Utilisateur user;
private readonly BindingSource bdgGenres = new BindingSource(); private readonly BindingSource bdgGenres = new BindingSource();
private readonly BindingSource bdgPublics = new BindingSource(); private readonly BindingSource bdgPublics = new BindingSource();
private readonly BindingSource bdgRayons = new BindingSource(); private readonly BindingSource bdgRayons = new BindingSource();
@ -27,20 +28,32 @@ namespace MediaTekDocuments.view
/// <summary> /// <summary>
/// Constructeur : création du contrôleur lié à ce formulaire /// Constructeur : création du contrôleur lié à ce formulaire
/// </summary> /// </summary>
public FrmMediatek() public FrmMediatek(Utilisateur user)
{ {
InitializeComponent(); InitializeComponent();
this.controller = new FrmMediatekController(); this.controller = new FrmMediatekController();
this.controller = new FrmMediatekController(); this.user = user;
this.Text += " - " + user.Prenom + " " + user.Nom;
RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuivi); RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuivi);
RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuiviDvd); RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuiviDvd);
cboSuivi.SelectedIndex = 0; cboSuivi.SelectedIndex = 0;
cboSuiviDvd.SelectedIndex = 0; cboSuiviDvd.SelectedIndex = 0;
if(user.LibelleService == "Prêts")
{
AlerteAbonnementsExpirants(); AlerteAbonnementsExpirants();
} }
if(user.LibelleService == "Administratif")
{
tabOngletsApplication.TabPages.Remove(tabCommandesRevues);
tabOngletsApplication.TabPages.Remove(tabCommandeLivres);
tabOngletsApplication.TabPages.Remove(tabCommandeDvd);
}
}
/// <summary> /// <summary>
/// Rempli un des 3 combo (genre, public, rayon) /// Rempli un des 3 combo (genre, public, rayon)
/// </summary> /// </summary>
@ -94,8 +107,18 @@ namespace MediaTekDocuments.view
dgvLivresListe.Columns["id"].DisplayIndex = 0; dgvLivresListe.Columns["id"].DisplayIndex = 0;
dgvLivresListe.Columns["titre"].DisplayIndex = 1; dgvLivresListe.Columns["titre"].DisplayIndex = 1;
dgvListeLivre2.DataSource = livres; RemplirDgvListeLivre2(livres);
}
private void RemplirDgvListeLivre2(List<Livre> livres)
{
if (tabOngletsApplication.TabPages.Contains(tabCommandeLivres))
{
dgvListeLivre2.DataSource = null;
dgvListeLivre2.DataSource = bdgLivresListe; dgvListeLivre2.DataSource = bdgLivresListe;
if (dgvListeLivre2.Columns.Count > 0 && dgvListeLivre2.Columns.Contains("isbn"))
{
dgvListeLivre2.Columns["isbn"].Visible = false; dgvListeLivre2.Columns["isbn"].Visible = false;
dgvListeLivre2.Columns["idRayon"].Visible = false; dgvListeLivre2.Columns["idRayon"].Visible = false;
dgvListeLivre2.Columns["idGenre"].Visible = false; dgvListeLivre2.Columns["idGenre"].Visible = false;
@ -105,6 +128,8 @@ namespace MediaTekDocuments.view
dgvListeLivre2.Columns["id"].DisplayIndex = 0; dgvListeLivre2.Columns["id"].DisplayIndex = 0;
dgvListeLivre2.Columns["titre"].DisplayIndex = 1; dgvListeLivre2.Columns["titre"].DisplayIndex = 1;
} }
}
}
/// <summary> /// <summary>
/// Recherche et affichage du livre dont on a saisi le numéro. /// Recherche et affichage du livre dont on a saisi le numéro.
@ -421,8 +446,18 @@ namespace MediaTekDocuments.view
dgvDvdListe.Columns["id"].DisplayIndex = 0; dgvDvdListe.Columns["id"].DisplayIndex = 0;
dgvDvdListe.Columns["titre"].DisplayIndex = 1; dgvDvdListe.Columns["titre"].DisplayIndex = 1;
dgvDvd.DataSource = Dvds; RemplirDgvDvd(Dvds);
}
private void RemplirDgvDvd(List<Dvd> dvds)
{
if (tabOngletsApplication.TabPages.Contains(tabCommandeDvd))
{
dgvDvd.DataSource = null;
dgvDvd.DataSource = bdgDvdListe; dgvDvd.DataSource = bdgDvdListe;
if (dgvDvd.Columns.Count > 0 && dgvDvd.Columns.Contains("idRayon"))
{
dgvDvd.Columns["idRayon"].Visible = false; dgvDvd.Columns["idRayon"].Visible = false;
dgvDvd.Columns["idGenre"].Visible = false; dgvDvd.Columns["idGenre"].Visible = false;
dgvDvd.Columns["idPublic"].Visible = false; dgvDvd.Columns["idPublic"].Visible = false;
@ -432,6 +467,8 @@ namespace MediaTekDocuments.view
dgvDvd.Columns["id"].DisplayIndex = 0; dgvDvd.Columns["id"].DisplayIndex = 0;
dgvDvd.Columns["titre"].DisplayIndex = 1; dgvDvd.Columns["titre"].DisplayIndex = 1;
} }
}
}
/// <summary> /// <summary>
/// Recherche et affichage du Dvd dont on a saisi le numéro. /// Recherche et affichage du Dvd dont on a saisi le numéro.

View file

@ -120,7 +120,4 @@
<metadata name="cboSuiviDvd.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="cboSuiviDvd.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="cboSuiviDvd.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>