Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version

This commit is contained in:
Jean-Daniel Lamontagne 2022-11-01 09:20:20 -04:00
commit 9814bf9b97
2 changed files with 30 additions and 12 deletions

View File

@ -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<InventoryContext>(options => { options.UseS
builder.Services.AddSingleton<DatabaseCacheService>();
builder.Services.BuildServiceProvider().GetRequiredService<DatabaseCacheService>();
var app = builder.Build();
// Configure the HTTP request pipeline.

View File

@ -5,28 +5,49 @@ const Login = () => {
const [adresse, setAdresse] = 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({ adresse, 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).
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 (
<div className="inventaire-form-container">
<h1>{kookees}</h1>
<form className="form-horizontal" onSubmit={handleLogin}>
<h4 className="text-center">Connexion</h4>
<div>
<h5>{returnmess}</h5>
</div>
<div className="form-group">
<label>Adresse courriel </label>
<input className="form-control form-input" type='text'