From f0fc91383a89b8ac025e7a599d195ea2b36eeafd Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Tue, 1 Nov 2022 08:55:01 -0700 Subject: [PATCH] PURT DAT KOOKEE DAOWN, NAOW!!! --- GrossesMitaines/GrossesMitainesAPI/Program.cs | 7 ++-- .../grosses-mitaines-ui/src/pages/Login.js | 33 +++++++++++++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Program.cs b/GrossesMitaines/GrossesMitainesAPI/Program.cs index 58230ea..d45ed1c 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Program.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Program.cs @@ -10,7 +10,6 @@ using System.Net; var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. builder.Services.AddCors(options => { options.AddPolicy(name: MyAllowSpecificOrigins, @@ -18,7 +17,8 @@ builder.Services.AddCors(options => { policy.WithOrigins("http://localhost:3000", "http://localhost:3001") .AllowAnyMethod() - .AllowAnyHeader(); + .AllowAnyHeader() + .AllowCredentials(); }); }); @@ -57,9 +57,6 @@ builder.Services.AddDbContextFactory(options => { options.UseS builder.Services.AddSingleton(); builder.Services.BuildServiceProvider().GetRequiredService(); - - - var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js index 478bfdc..2b37d2d 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js @@ -5,28 +5,49 @@ const Login = () => { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); - const [kookees, setCookies] = useState(""); + const [returnmess, returnMessage] = useState(""); const handleLogin = async (e) => { e.preventDefault(); const response = await fetch(`https://localhost:7292/api/Login?rememberMe=true`, { method: 'POST', + credentials: 'include', headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + 'Accept': 'text/json', + 'Content-Type': 'text/json' }, body: JSON.stringify({ username, password }) - }) + }); // Partie de display d'erreur ou de redirection (faudrait checker pour se faire un state de connexion avec un cookie pour react). - + + if (response.status === 200) { + var rep = await response.json(); + if (rep.succeeded === true) { + const confirm = await fetch(`https://localhost:7292/api/Login`, { + method: 'GET', + credentials: 'include', + headers: { + 'Accept': 'text/json', + 'Content-Type': 'text/json' + } + }); + console.log(await confirm.json()) + returnMessage("WOOHOO!"); + } + else returnMessage("Le nom d'Utilisateur ou le mot de passe est incorrect."); + } + else returnMessage("Erreur d'API.") } return (
-

{kookees}

+

Connexion

+
+
{returnmess}
+