working login for students and logout
This commit is contained in:
parent
9c07472aca
commit
28dd929927
2 changed files with 32 additions and 14 deletions
|
|
@ -3,7 +3,7 @@ import "@fortawesome/fontawesome-free/css/all.min.css";
|
||||||
|
|
||||||
function SignInForm() {
|
function SignInForm() {
|
||||||
const [state, setState] = React.useState({
|
const [state, setState] = React.useState({
|
||||||
email: "",
|
assignmentID: "",
|
||||||
password: "",
|
password: "",
|
||||||
});
|
});
|
||||||
const handleChange = (evt) => {
|
const handleChange = (evt) => {
|
||||||
|
|
@ -17,15 +17,33 @@ function SignInForm() {
|
||||||
const handleOnSubmit = (evt) => {
|
const handleOnSubmit = (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
const { email, password } = state;
|
const { assignmentId, password } = state;
|
||||||
alert(`You are login with email: ${email} and password: ${password}`);
|
console.log(`You are loggind in with email: ${assignmentId} and password: ${password}`);
|
||||||
|
|
||||||
for (const key in state) {
|
console.log("Submitting login request with state:", state);
|
||||||
setState({
|
fetch("http://localhost:8080/auth/student/login", {
|
||||||
...state,
|
method: "POST",
|
||||||
[key]: "",
|
headers: {
|
||||||
});
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(state),
|
||||||
|
credentials: "include",
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log("Received response:", response);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Network response was not ok");
|
||||||
}
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
console.log("Success:", data);
|
||||||
|
window.location.href = "/";
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error occurred during login:", error);
|
||||||
|
alert("Login failed!");
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -39,10 +57,10 @@ function SignInForm() {
|
||||||
</div> */}
|
</div> */}
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="assignmentId"
|
||||||
placeholder="Student Name"
|
placeholder="Assignment ID"
|
||||||
name="email"
|
name="assignmentId"
|
||||||
value={state.email}
|
value={state.assignmentId}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ function SignUpForm() {
|
||||||
const handleOnSubmit = (evt) => {
|
const handleOnSubmit = (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
const { name, email, password } = state;
|
const { assignmentID, password } = state;
|
||||||
alert(
|
alert(
|
||||||
`You are signed in with name: ${name} email: ${email} and password: ${password}`
|
`You are signed in with assignmentID: ${assignmentID} and password: ${password}`
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const key in state) {
|
for (const key in state) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue