react-version #1
@ -23,8 +23,27 @@ builder.Services.AddCors(options => {
|
||||
});
|
||||
|
||||
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>()
|
||||
.AddRoles<IdentityRole>()
|
||||
.AddEntityFrameworkStores<InventoryContext>()
|
||||
@ -52,7 +71,6 @@ if (app.Environment.IsDevelopment()) {
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseCors(MyAllowSpecificOrigins);
|
||||
|
||||
app.UseAuthorization();
|
||||
app.UseAuthentication();
|
||||
|
||||
|
@ -29,7 +29,7 @@ const Home = () => {
|
||||
<h4 className="home-subtitle">(à Ginette et Monique)</h4>
|
||||
<img src="/images/LesGrossesMitaines.png" className="home-img" alt="home"/>
|
||||
<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>
|
||||
<FeaturedList
|
||||
products={products}
|
||||
|
@ -5,11 +5,12 @@ const Login = () => {
|
||||
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [kookees, setCookies] = useState("");
|
||||
|
||||
const handleLogin = async (e) => {
|
||||
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',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
@ -17,13 +18,13 @@ const Login = () => {
|
||||
},
|
||||
body: JSON.stringify({ username, password })
|
||||
})
|
||||
|
||||
// Partie de display d'erreur ou de redirection (faudrait checker pour se faire un state de connexion).
|
||||
// Partie de display d'erreur ou de redirection (faudrait checker pour se faire un state de connexion avec un cookie pour react).
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="inventaire-form-container">
|
||||
<h1>{kookees}</h1>
|
||||
<form className="form-horizontal" onSubmit={handleLogin}>
|
||||
<h4 className="text-center">Connexion</h4>
|
||||
<div className="form-group">
|
||||
|
Loading…
Reference in New Issue
Block a user