PURT DAT KOOKEE DAOWN, NAOW!!!

This commit is contained in:
MarcEricMartel 2022-11-01 08:55:01 -07:00
parent bbff60ca54
commit f0fc91383a
2 changed files with 29 additions and 11 deletions

View File

@ -10,7 +10,6 @@ using System.Net;
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddCors(options => { builder.Services.AddCors(options => {
options.AddPolicy(name: MyAllowSpecificOrigins, options.AddPolicy(name: MyAllowSpecificOrigins,
@ -18,7 +17,8 @@ builder.Services.AddCors(options => {
policy.WithOrigins("http://localhost:3000", policy.WithOrigins("http://localhost:3000",
"http://localhost:3001") "http://localhost:3001")
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader(); .AllowAnyHeader()
.AllowCredentials();
}); });
}); });
@ -57,9 +57,6 @@ builder.Services.AddDbContextFactory<InventoryContext>(options => { options.UseS
builder.Services.AddSingleton<DatabaseCacheService>(); builder.Services.AddSingleton<DatabaseCacheService>();
builder.Services.BuildServiceProvider().GetRequiredService<DatabaseCacheService>(); builder.Services.BuildServiceProvider().GetRequiredService<DatabaseCacheService>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

View File

@ -5,28 +5,49 @@ const Login = () => {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [kookees, setCookies] = useState(""); const [returnmess, returnMessage] = useState("");
const handleLogin = async (e) => { const handleLogin = async (e) => {
e.preventDefault(); e.preventDefault();
const response = await fetch(`https://localhost:7292/api/Login?rememberMe=true`, { const response = await fetch(`https://localhost:7292/api/Login?rememberMe=true`, {
method: 'POST', method: 'POST',
credentials: 'include',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'text/json',
'Content-Type': 'application/json' 'Content-Type': 'text/json'
}, },
body: JSON.stringify({ username, password }) 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). // 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 ( return (
<div className="inventaire-form-container"> <div className="inventaire-form-container">
<h1>{kookees}</h1>
<form className="form-horizontal" onSubmit={handleLogin}> <form className="form-horizontal" onSubmit={handleLogin}>
<h4 className="text-center">Connexion</h4> <h4 className="text-center">Connexion</h4>
<div>
<h5>{returnmess}</h5>
</div>
<div className="form-group"> <div className="form-group">
<label>Nom Utilisateur: </label> <label>Nom Utilisateur: </label>
<input className="form-control form-input" type='text' <input className="form-control form-input" type='text'