Loading dans le login et correction de fuck de login dans l'API
This commit is contained in:
parent
f197c05b0c
commit
43cd2bd7c2
@ -46,6 +46,8 @@ public class LoginController : Controller {
|
|||||||
public SignInResult Login(LoginModel user, bool rememberMe = false) {
|
public SignInResult Login(LoginModel user, bool rememberMe = false) {
|
||||||
var User = _userMan.FindByEmailAsync(user.email.ToUpper());
|
var User = _userMan.FindByEmailAsync(user.email.ToUpper());
|
||||||
User.Wait();
|
User.Wait();
|
||||||
|
if (User.Result is null)
|
||||||
|
return new SignInResult();
|
||||||
var res = _signInMan.PasswordSignInAsync(User.Result, user.password, rememberMe, false);
|
var res = _signInMan.PasswordSignInAsync(User.Result, user.password, rememberMe, false);
|
||||||
res.Wait();
|
res.Wait();
|
||||||
return res.Result;
|
return res.Result;
|
||||||
|
@ -23,9 +23,9 @@ const App = () => {
|
|||||||
const response = await fetch(`https://localhost:7292/api/WhoAmI`, { credentials: 'include' });
|
const response = await fetch(`https://localhost:7292/api/WhoAmI`, { credentials: 'include' });
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
var user = await response.json();
|
var user = await response.json();
|
||||||
setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', sameSite:'strict' })
|
setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', SameSite:'strict' })
|
||||||
}
|
}
|
||||||
else setCookie('GMGM', {LoggedIn:false}, { path: '/', sameSite:'strict' })
|
else setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' })
|
||||||
}
|
}
|
||||||
if (cookies.GMGM === null) {
|
if (cookies.GMGM === null) {
|
||||||
FetchUser();
|
FetchUser();
|
||||||
|
@ -14,14 +14,14 @@ const Topbar = () => {
|
|||||||
setLogin(cookies.GMGM ?? null);
|
setLogin(cookies.GMGM ?? null);
|
||||||
});
|
});
|
||||||
|
|
||||||
function logOut() {
|
async function logOut() {
|
||||||
const response = fetch(`https://localhost:7292/api/Logout`, {
|
const response = fetch(`https://localhost:7292/api/Logout`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
|
|
||||||
removeCookie("GMGM");
|
await removeCookie("GMGM");
|
||||||
setLogin(null); // Y U NO WORK?!?
|
await setLogin(null); // Y U NO WORK?!?
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -9,10 +9,12 @@ const Login = () => {
|
|||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [returnmess, returnMessage] = useState("");
|
const [returnmess, returnMessage] = useState("");
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleLogin = async (e) => {
|
const handleLogin = async (e) => {
|
||||||
|
setLoading(true);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const response = await fetch(`https://localhost:7292/api/Login?rememberMe=${rememberme}`, {
|
const response = await fetch(`https://localhost:7292/api/Login?rememberMe=${rememberme}`, {
|
||||||
@ -37,21 +39,24 @@ const Login = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const user = await confirm.json();
|
const user = await confirm.json();
|
||||||
setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', sameSite:'strict' })
|
setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', SameSite:'strict' })
|
||||||
navigate("/");
|
navigate("/");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
returnMessage("L'adresse courriel ou le mot de passe est incorrect.");
|
returnMessage("L'adresse courriel ou le mot de passe est incorrect.");
|
||||||
setCookie('GMGM', {LoggedIn:false}, { path: '/', sameSite:'strict' })
|
setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
returnMessage("Erreur d'API, veuillez réessayer plus tard.")
|
returnMessage("Erreur d'API, veuillez réessayer plus tard.")
|
||||||
setCookie('GMGM', {LoggedIn:false}, { path: '/', sameSite:'strict' })
|
setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' })
|
||||||
}
|
}
|
||||||
setPassword("");
|
setPassword("");
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isLoading) return (<div className="cat-load"/>)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="inventaire-form-container">
|
<div className="inventaire-form-container">
|
||||||
|
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
import { useCookies } from "react-cookie";
|
import { useCookies } from "react-cookie";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
const Logout = () => {
|
const Logout = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [cookies, setCookie, removeCookie] = useCookies(['name']);
|
const [cookies, setCookie, removeCookie] = useCookies(['name']);
|
||||||
|
|
||||||
|
|
||||||
const response = fetch(`https://localhost:7292/api/Logout`, {
|
const response = fetch(`https://localhost:7292/api/Logout`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
|
|
||||||
removeCookie("GMGM");
|
async function clear() {
|
||||||
|
await removeCookie("GMGM");
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
|
clear();
|
||||||
navigate("/");
|
navigate("/");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user