import { Alert, CircularProgress, FormControl, IconButton, InputAdornment, InputLabel, OutlinedInput, Tooltip, } from "@mui/material"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Grid from "@mui/material/Grid"; import TextField from "@mui/material/TextField"; import Typography from "@mui/material/Typography"; import * as React from "react"; import { AuthApi, PasswordLoginResult } from "../../api/AuthApi"; import { ServerApi } from "../../api/ServerApi"; import { Link, useNavigate } from "react-router-dom"; import { VisibilityOff, Visibility } from "@mui/icons-material"; import { useSetAtom } from "jotai"; /** * Login form */ export function LoginRoute(): React.ReactElement { const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState(null); const setAuth = useSetAtom(AuthApi.authStatus); const navigate = useNavigate(); const [mail, setMail] = React.useState(""); const [password, setPassword] = React.useState(""); const canSubmit = mail.length > 0 && password.length > 0; const [showPassword, setShowPassword] = React.useState(false); const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = ( event: React.MouseEvent ) => { event.preventDefault(); }; const handleLoginSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!canSubmit) return; try { const res = await AuthApi.LoginWithPassword(mail, password); switch (res) { case PasswordLoginResult.TooManyRequests: setError( "Trop de tentatives de connection. Veuillez réessayer ultérieurement." ); break; case PasswordLoginResult.InvalidCredentials: setError("Identifiants saisis invalides !"); break; case PasswordLoginResult.Success: navigate("/"); setAuth(true); break; case PasswordLoginResult.Error: setError("Echec de la connexion !"); break; } } catch (e) { console.error(e); setError("Echec de l'authentification !"); } setLoading(false); }; const authWithProvider = async (id: string) => { try { setLoading(true); const res = await AuthApi.StartOpenIDLogin(id); window.location.href = res.url; } catch (e) { console.error(e); setError("Echec de l'initialisation de l'authentification OpenID !"); } }; if (loading) return ( <> ); return ( <> {error && ( {error} )} Connexion setMail(e.target.value)} autoComplete="email" autoFocus /> Mot de passe setPassword(e.target.value)} autoComplete="current-password" endAdornment={ {showPassword ? : } } /> Mot de passe oublié Créer un nouveau compte
{ServerApi.Config.oidc_providers.map((p) => ( ))}
); }