Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version
This commit is contained in:
commit
00667c833f
@ -23,8 +23,27 @@ builder.Services.AddCors(options => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
builder.Services.AddAuthentication().AddIdentityCookies();
|
||||||
|
|
||||||
|
// Source: https://github.com/dotnet/aspnetcore/issues/9039
|
||||||
|
builder.Services.ConfigureApplicationCookie(o => {
|
||||||
|
o.Events = new CookieAuthenticationEvents() {
|
||||||
|
OnRedirectToLogin = (ctx) => {
|
||||||
|
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200) {
|
||||||
|
ctx.Response.StatusCode = 401;
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
},
|
||||||
|
OnRedirectToAccessDenied = (ctx) => {
|
||||||
|
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200) {
|
||||||
|
ctx.Response.StatusCode = 403;
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddAuthentication("Cookies").AddIdentityCookies();
|
|
||||||
builder.Services.AddIdentityCore<InventoryUser>()
|
builder.Services.AddIdentityCore<InventoryUser>()
|
||||||
.AddRoles<IdentityRole>()
|
.AddRoles<IdentityRole>()
|
||||||
.AddEntityFrameworkStores<InventoryContext>()
|
.AddEntityFrameworkStores<InventoryContext>()
|
||||||
@ -52,7 +71,6 @@ if (app.Environment.IsDevelopment()) {
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseCors(MyAllowSpecificOrigins);
|
app.UseCors(MyAllowSpecificOrigins);
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ const Home = () => {
|
|||||||
<h4 className="home-subtitle">(à Ginette et Monique)</h4>
|
<h4 className="home-subtitle">(à Ginette et Monique)</h4>
|
||||||
<img src="/images/LesGrossesMitaines.png" className="home-img" alt="home"/>
|
<img src="/images/LesGrossesMitaines.png" className="home-img" alt="home"/>
|
||||||
<br/>
|
<br/>
|
||||||
<h2 className="home-description">Des produits bien commodes faits par des aînées d'expérience.</h2>
|
<h2 className="home-description">Des produits bien commodes faits par des aînées d'expérience. {document.cookie}</h2>
|
||||||
</div>
|
</div>
|
||||||
<FeaturedList
|
<FeaturedList
|
||||||
products={products}
|
products={products}
|
||||||
|
@ -5,11 +5,12 @@ const Login = () => {
|
|||||||
|
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const [kookees, setCookies] = 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',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
@ -17,13 +18,13 @@ const Login = () => {
|
|||||||
},
|
},
|
||||||
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).
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 className="form-group">
|
<div className="form-group">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user