2021-06-21 22:58:08 +00:00
|
|
|
import React from "react";
|
2021-06-22 23:26:55 +00:00
|
|
|
import { useState } from "react/cjs/react.development";
|
2021-06-21 22:58:08 +00:00
|
|
|
import "../../App.css";
|
|
|
|
import Footer from "../../Footer";
|
|
|
|
import InputField from "../InputField";
|
|
|
|
import SubmitField from "../SubmitField";
|
2021-06-29 22:58:44 +00:00
|
|
|
import "../Input.css";
|
2021-06-21 22:58:08 +00:00
|
|
|
|
|
|
|
export default function Login() {
|
2021-06-23 01:40:37 +00:00
|
|
|
const [username, setUsername] = useState("");
|
|
|
|
const [password, setPassword] = useState("");
|
2021-06-22 23:26:55 +00:00
|
|
|
|
2021-06-28 01:46:27 +00:00
|
|
|
const [message, setMessage] = useState("");
|
|
|
|
|
2021-06-23 01:40:37 +00:00
|
|
|
const onSubmitClick = (e) => {
|
2021-06-22 23:26:55 +00:00
|
|
|
e.preventDefault();
|
|
|
|
let opts = {
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
};
|
|
|
|
fetch("/api/register", {
|
|
|
|
method: "post",
|
|
|
|
body: JSON.stringify(opts),
|
2021-06-28 01:46:27 +00:00
|
|
|
}).then((response) => {
|
2021-06-29 22:58:44 +00:00
|
|
|
console.log(response);
|
2021-06-28 01:46:27 +00:00
|
|
|
if (response.status === 409) {
|
2021-06-29 22:03:34 +00:00
|
|
|
/*
|
|
|
|
then is needed twice to get rid of the javascript Promise thing
|
|
|
|
*/
|
|
|
|
response.json().then((resp2) => {
|
2021-06-29 22:58:44 +00:00
|
|
|
setMessage(resp2.message);
|
2021-06-29 22:03:34 +00:00
|
|
|
});
|
2021-06-29 22:58:44 +00:00
|
|
|
} else if (response.status === 200) {
|
2021-06-29 22:03:34 +00:00
|
|
|
//TODO redirect to login #77 or #74
|
2021-06-28 01:46:27 +00:00
|
|
|
}
|
2021-06-23 01:40:37 +00:00
|
|
|
});
|
2021-06-22 23:26:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleUsernameChange = (e) => {
|
|
|
|
setUsername(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handlePasswordChange = (e) => {
|
|
|
|
setPassword(e.target.value);
|
|
|
|
};
|
|
|
|
|
2021-06-21 22:58:08 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="sitePage">
|
|
|
|
<h1>Registrierung</h1>
|
|
|
|
<form>
|
|
|
|
<InputField
|
2021-06-23 01:16:09 +00:00
|
|
|
LabelName="Benutzername"
|
2021-06-22 23:26:55 +00:00
|
|
|
InputType="text"
|
|
|
|
onChange={handleUsernameChange}
|
2021-06-21 22:58:08 +00:00
|
|
|
InputName="username"
|
|
|
|
/>
|
2021-06-29 22:41:58 +00:00
|
|
|
<p className="errorMessage">{message}</p>
|
2021-06-21 22:58:08 +00:00
|
|
|
<InputField
|
|
|
|
LabelName="Passwort"
|
|
|
|
InputType="password"
|
2021-06-22 23:26:55 +00:00
|
|
|
onChange={handlePasswordChange}
|
2021-06-21 22:58:08 +00:00
|
|
|
InputName="password"
|
|
|
|
/>
|
|
|
|
<br />
|
2021-06-29 23:00:33 +00:00
|
|
|
<SubmitField onClick={onSubmitClick} LabelName="Registrieren" />
|
2021-06-21 22:58:08 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|