import { useState } from 'react'; import { Form, Button, Alert, Col, Row } from 'react-bootstrap'; import { useNavigate } from 'react-router'; import API from '../API.js' function TotpForm(props) { const [totpCode, setTotpCode] = useState(''); const [errorMessage, setErrorMessage] = useState(''); const navigate = useNavigate(); const doTotpVerify = () => { API.totpVerify(totpCode) .then(() => { setErrorMessage(''); props.totpSuccessful(); navigate('/'); }) .catch(() => { setErrorMessage('Something went wrong, please try again'); }) } const handleSubmit = (event) => { event.preventDefault(); setErrorMessage(''); let valid = true; if(totpCode === '' || totpCode.length !== 6) valid = false; if (valid) { doTotpVerify(totpCode); } else { setErrorMessage('Invalid content in form: either empty or not 6-char long'); } }; return (

Second Factor Authentication

Please enter the code that you read on your device
{errorMessage ? setErrorMessage('')}>{errorMessage} : ''} Code setTotpCode(ev.target.value)} />
) } function LoginForm(props) { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [istotp, setIstotp] = useState(false); const [errorMessage, setErrorMessage] = useState(''); const navigate = useNavigate(); const handleSubmit = (event) => { event.preventDefault(); const credentials = { username, password }; if (!username) { setErrorMessage('Username cannot be empty'); } else if (!password) { setErrorMessage('Password cannot be empty'); } else { props.login(credentials) .catch((err) => { setErrorMessage(err.error); }); } }; return (

Login

{errorMessage? setErrorMessage('')} variant="danger">{errorMessage} : null} Username setUsername(ev.target.value)} /> Password setPassword(ev.target.value)} /> setIstotp(ev.target.value)} />
) }; function LogoutButton(props) { return ( ) } function LoginButton(props) { const navigate = useNavigate(); return ( ) } export { LoginForm, LogoutButton, LoginButton, TotpForm };