2024-03-09 09:45:33 +01:00
|
|
|
import {useState} from "react";
|
2024-03-09 22:32:04 +01:00
|
|
|
import {useStore} from "../store/store.ts";
|
|
|
|
import {useNavigate} from "react-router-dom";
|
2024-03-09 09:45:33 +01:00
|
|
|
|
|
|
|
export const LoginScreen = ()=>{
|
2024-03-09 22:32:04 +01:00
|
|
|
const navigate = useNavigate()
|
2024-03-09 09:45:33 +01:00
|
|
|
const [username, setUsername] = useState('')
|
|
|
|
const [password, setPassword] = useState('')
|
|
|
|
|
|
|
|
const login = ()=>{
|
2024-03-09 22:32:04 +01:00
|
|
|
fetch('/admin-auth/', {
|
|
|
|
method: 'POST',
|
2024-03-09 09:45:33 +01:00
|
|
|
headers:{
|
|
|
|
Authorization: `Basic ${btoa(`${username}:${password}`)}`
|
|
|
|
}
|
|
|
|
}).then(r=>{
|
2024-03-09 22:32:04 +01:00
|
|
|
if(!r.ok) {
|
|
|
|
useStore.getState().setToastState({
|
|
|
|
open: true,
|
|
|
|
title: "Login failed",
|
|
|
|
success: false
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
navigate('/')
|
|
|
|
}
|
2024-03-09 09:45:33 +01:00
|
|
|
}).catch(e=>{
|
|
|
|
console.error(e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="login-background">
|
|
|
|
<div className="login-box">
|
|
|
|
<h1 className="login-title">Login Etherpad</h1>
|
|
|
|
<div className="login-inner-box">
|
|
|
|
<div>Username</div>
|
|
|
|
<input className="login-textinput" type="text" value={username} onChange={v => setUsername(v.target.value)} placeholder="Username"/>
|
|
|
|
<div>Passwort</div>
|
|
|
|
<input className="login-textinput" type="password" value={password}
|
|
|
|
onChange={v => setPassword(v.target.value)} placeholder="Password"/>
|
|
|
|
<input type="button" value="Login" onClick={login} className="login-button"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|