From 83c90987aaec669f7c4b2907be5c59fe7da52fb6 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Thu, 15 Feb 2024 16:40:18 +0100 Subject: [PATCH] Created the Login.jsx state --- webui/src/states/Login/Login.jsx | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/webui/src/states/Login/Login.jsx b/webui/src/states/Login/Login.jsx index 8b8d114..165de13 100644 --- a/webui/src/states/Login/Login.jsx +++ b/webui/src/states/Login/Login.jsx @@ -1,7 +1,53 @@ +import {useContext, useState} from "react"; +import {TokenContext} from "@/common/contexts/Token"; +import {Navigate} from "react-router-dom"; +import {Alert, Box, Button, Container, Divider, Grid, Stack, TextField, Typography} from "@mui/material"; +import {t} from "i18next"; + export const Login = () => { + const {tokenValid, checkToken} = useContext(TokenContext); + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [loginFailed, setLoginFailed] = useState(false); + + const login = (e) => { + if (e) e.preventDefault(); + localStorage.setItem("token", btoa(`${username}:${password}`)); + checkToken().then((r) => setLoginFailed(!r)); + } + return (
-

Login

+ {tokenValid && } + + + + + + MCDash + MCDash + + {t("login.sign_in")} + + {loginFailed && + {t("login.failed")} + } + + setUsername(e.target.value)}/> + + setPassword(e.target.value)}/> + + + + + +
- ) -} \ No newline at end of file + ); +};