From 12fefde1d7a7270a15761812c0b4568a0ef040e8 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Tue, 3 Jan 2023 09:51:03 +0100 Subject: [PATCH] Ajout de Route --- Sources/API/routes/Inscrit.php | 33 ++++++++++++ Sources/Data/ClientAPI.cs | 24 +++++++++ Sources/Data/PersAPI.cs | 9 +++- Sources/Data/PersLinqToPgSQL.cs | 2 +- Sources/Data/PersStub.cs | 7 +-- Sources/IHM/Mobile/Inscription.xaml.cs | 8 +-- Sources/Modele/Manager.cs | 74 +------------------------- Sources/TestFonctionnel/Program.cs | 12 +++++ 8 files changed, 85 insertions(+), 84 deletions(-) diff --git a/Sources/API/routes/Inscrit.php b/Sources/API/routes/Inscrit.php index 54ebb12..88902fb 100644 --- a/Sources/API/routes/Inscrit.php +++ b/Sources/API/routes/Inscrit.php @@ -138,4 +138,37 @@ $app->post('/Inscrit/add/', function(Request $request, Response $response, array ->withStatus(500); } }); + + + +$app->delete('/Inscrit/delete/', function (Request $request, Response $response, array $args) { + $email = $request->getParsedBody()["email"]; + + $query = "DELETE FROM Inscrit WHERE mail=:mail"; + + try{ + $db = new Database(); + $conn = $db->connect(); + + $stmt = $conn->prepare($query); + $stmt->bindValue(':mail', $email, PDO::PARAM_STR); + + $result = $stmt->execute(); + + $db = null; + $response->getBody()->write(json_encode($result)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(200); + + } catch(PDOException $e){ + $error = array("message" => $e->getMessage()); + + $response->getBody()->write(json_encode($error)); + return $response + ->withHeader('content-type', 'application/json') + ->withStatus(500); + } +}); + ?> \ No newline at end of file diff --git a/Sources/Data/ClientAPI.cs b/Sources/Data/ClientAPI.cs index d78f859..7b78c05 100644 --- a/Sources/Data/ClientAPI.cs +++ b/Sources/Data/ClientAPI.cs @@ -22,6 +22,7 @@ namespace Data private const string POST_EMAIL_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/FromMail/"; private const string PUT_PASSWORD_INSCRIT_DATA_URL = ROOT_URL+"Inscrit/UpdatePassword/"; private const string POST_ADD_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/add/"; + private const string DELETE_INSCRIT_DATA_URL = ROOT_URL + "Inscrit/delete/"; //add all routes @@ -89,5 +90,28 @@ namespace Data } + public static async Task DeleteInscritAsync(string email) + { + var dataBody = new Dictionary { { "email", email } }; + + var reponse = + cli.SendAsync( + new HttpRequestMessage(HttpMethod.Delete, DELETE_INSCRIT_DATA_URL) + { + Content = new FormUrlEncodedContent(dataBody) + }) + .Result; + + if (reponse.IsSuccessStatusCode) + { + return true; + } + else + { + throw new HttpRequestException(reponse.StatusCode.ToString()); + } + + } + } } diff --git a/Sources/Data/PersAPI.cs b/Sources/Data/PersAPI.cs index 472a16a..162af67 100644 --- a/Sources/Data/PersAPI.cs +++ b/Sources/Data/PersAPI.cs @@ -19,7 +19,7 @@ namespace Data } public bool SupprimerInscrit(Inscrit inscrit) { - throw new NotImplementedException(); + return ClientAPI.DeleteInscritAsync(inscrit.Mail).GetAwaiter().GetResult(); } public bool ModifierMdpInscrit(string mail, string nouveauMdp) { @@ -36,7 +36,12 @@ namespace Data } public bool EmailDisponible(string mail) { - throw new NotImplementedException(); + List inscrits = ClientAPI.GetInscritAsync(mail).GetAwaiter().GetResult(); + if (inscrits.Count >= 1) + { + return false; + } + return true; } diff --git a/Sources/Data/PersLinqToPgSQL.cs b/Sources/Data/PersLinqToPgSQL.cs index 1a86bbe..52a82a9 100644 --- a/Sources/Data/PersLinqToPgSQL.cs +++ b/Sources/Data/PersLinqToPgSQL.cs @@ -17,7 +17,7 @@ using System.Reflection.PortableExecutable; namespace LinqToPgSQL { - public class PersLinqToPgSQL : IPersistanceManager + public class PersLinqToPgSQL /*: IPersistanceManager*/ { private Hash hash = new Hash(); private static string connexionBDD = String.Format("Server=2.3.8.130; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); diff --git a/Sources/Data/PersStub.cs b/Sources/Data/PersStub.cs index 62b0c8c..e209d82 100644 --- a/Sources/Data/PersStub.cs +++ b/Sources/Data/PersStub.cs @@ -2,7 +2,7 @@ namespace Data { - public class PersStub : IPersistanceManager + public class PersStub /*: IPersistanceManager*/ { private List lesInscrits = new List(); @@ -122,10 +122,7 @@ namespace Data return LoadOperation.LoadOperationsFromOFX(ofx); } - string IPersistanceManager.GetId(string mail) - { - throw new NotImplementedException(); - } + public List LoadBanqueId(int id) { diff --git a/Sources/IHM/Mobile/Inscription.xaml.cs b/Sources/IHM/Mobile/Inscription.xaml.cs index ff425a5..3a5ddc5 100644 --- a/Sources/IHM/Mobile/Inscription.xaml.cs +++ b/Sources/IHM/Mobile/Inscription.xaml.cs @@ -20,7 +20,7 @@ public partial class Inscription : ContentPage } else { - if(EntryNewPassword.Text.Equals(EntryConfirmationPassword.Text)) { + /*if(EntryNewPassword.Text.Equals(EntryConfirmationPassword.Text)) { if (Mgr.existEmail(EntryNewMail.Text)) { AffichError("Mail existant", "un compte porte déjà cette adresse mail, veuillez en changer", "OK"); @@ -43,15 +43,15 @@ public partial class Inscription : ContentPage else { AffichError("Mot de passe de confirmation invalide", "Veuillez mettre deux mots de passe identiques", "OK"); - } + }*/ } } private void ValideCode(object sender, EventArgs e) { if (EntryCodeRecept.Text == code) { - Inscrit inscrit = new Inscrit(Mgr.lastInscrit() + 1, EntryNewName.Text, EntryNewMail.Text, EntryNewSurname.Text, EntryNewPassword.Text); - Mgr.createInscrit(inscrit); + //Inscrit inscrit = new Inscrit(Mgr.lastInscrit() + 1, EntryNewName.Text, EntryNewMail.Text, EntryNewSurname.Text, EntryNewPassword.Text); + //Mgr.createInscrit(inscrit); AffichError("compte créé", "Compte bien créé", "OK"); NavigateTo(".."); } diff --git a/Sources/Modele/Manager.cs b/Sources/Modele/Manager.cs index 0ca01b4..59e2912 100644 --- a/Sources/Modele/Manager.cs +++ b/Sources/Modele/Manager.cs @@ -79,91 +79,21 @@ namespace Model Pers = persistance; } - public void SupprimerInscritBdd(Inscrit i) - { - Pers.SupprimerInscritBdd(i); - } - - public string GetId(string mail) - { - return Pers.GetId(mail); - } - - public void LoadBanques() - { - User.LesBanques = Pers.LoadBanqueId(User.Id); - if (User.LesBanques.Count() > 0) - { - SelectedBanque = User.LesBanques[0]; - } - } - - public void supprimerToutesBanquesBdd(Inscrit inscrit) - { - Pers.SupprimerToutesBanquesBdd(inscrit); - } - - public void createInscrit(Inscrit inscrit) - { - Pers.CreateInscrit(inscrit); - } - - public string lastInscrit() - { - return Pers.LastInscrit(); - } - - public bool existEmail(string mail) - { - return Pers.ExistEmail(mail); - } - - public void changePasswordBdd(string mail, string newMdp) - { - Pers.ChangePasswordBdd(mail, newMdp); - } - - public string recupMdpBdd(string mail) - { - return Pers.RecupMdpBdd(mail); - } + public bool isEqualHash(string mdpBdd, string mdpSent) { return hash.IsEqualHash(mdpBdd, mdpSent); } - public void createUser(string mail) - { - //User = new Inscrit(mail, GetId(mail)); - User = Pers.GetInscrit(mail); - } - - public int recupTotalSolde() - { - Solde = Pers.CalculTotalSoldeComtpe(User); - return Solde; - } + public void deconnexion() { User = null; } - public bool testConnexionAsDatabase() - { - return Pers.TestConnexionAsDatabase(); - } - - public void importBanques() - { - BanquesDisponibleInApp = Pers.ImportBanques(); - } - public IList getCompteFromOFX(string ofx) - { - return Pers.GetCompteFromOFX(ofx); - } } } diff --git a/Sources/TestFonctionnel/Program.cs b/Sources/TestFonctionnel/Program.cs index 6db5c86..98e9e7f 100644 --- a/Sources/TestFonctionnel/Program.cs +++ b/Sources/TestFonctionnel/Program.cs @@ -57,6 +57,18 @@ Console.WriteLine("\n----Resultats----\n"); IList modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); foreach (Inscrit i in modif) +{ + Console.WriteLine(i); +} + +Console.WriteLine("\n----Modifs----\n"); + +bool rrr = ClientAPI.DeleteInscritAsync("livet.hugo2003@gmail.com").GetAwaiter().GetResult(); +Console.WriteLine("Del user : " + rr + "\n"); + + +modif = ClientAPI.GetInscritsAsync().GetAwaiter().GetResult(); +foreach (Inscrit i in modif) { Console.WriteLine(i); } \ No newline at end of file