2023-04-29 12:01:45 -04:00
|
|
|
import React,{useState, useEffect} from 'react';
|
2023-04-27 14:30:17 -04:00
|
|
|
import {Routes, Route, useNavigate} from 'react-router-dom';
|
2023-04-29 12:01:45 -04:00
|
|
|
import Axios from 'axios';
|
2023-04-27 14:30:17 -04:00
|
|
|
import './Login.css';
|
2023-04-29 16:15:28 -04:00
|
|
|
import Button from "@mui/material/Button";
|
|
|
|
|
import Card from "@mui/material/Card";
|
|
|
|
|
import TextField from "@mui/material/TextField";
|
|
|
|
|
import FormControlLabel from "@mui/material/FormControlLabel";
|
|
|
|
|
import Checkbox from "@mui/material/Checkbox";
|
|
|
|
|
import Link from "@mui/material/Link";
|
|
|
|
|
import Grid from "@mui/material/Grid";
|
|
|
|
|
import Box from "@mui/material/Box";
|
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
|
import Container from "@mui/material/Container";
|
|
|
|
|
import {red, green, lightBlue, lightGreen} from '@mui/material/colors';
|
|
|
|
|
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
|
|
|
import image from "./images/main_background.jpg"
|
2023-04-29 21:19:57 -04:00
|
|
|
import { ReactSession } from 'react-client-session';
|
2023-04-30 15:35:02 -04:00
|
|
|
import { CardMedia, CardContent } from '@mui/material';
|
2023-04-27 14:30:17 -04:00
|
|
|
|
2023-04-29 16:15:28 -04:00
|
|
|
const theme = createTheme({
|
|
|
|
|
palette: {
|
|
|
|
|
primary: {
|
|
|
|
|
main: lightGreen[700],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-04-29 12:01:45 -04:00
|
|
|
|
2023-04-29 21:19:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export function Login() {
|
2023-04-27 14:30:17 -04:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const navigateCreateAccount = () => {
|
|
|
|
|
navigate('/CreateAccount');
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-29 22:52:09 -04:00
|
|
|
const navigateHome = () => {
|
|
|
|
|
navigate('/Plan');
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-29 21:19:57 -04:00
|
|
|
const [data,setData] = useState({
|
2023-04-29 16:15:28 -04:00
|
|
|
net_id:"",
|
2023-04-27 14:30:17 -04:00
|
|
|
password:""
|
|
|
|
|
})
|
2023-04-29 21:19:57 -04:00
|
|
|
|
2023-04-29 16:15:28 -04:00
|
|
|
const {net_id,password} = data;
|
2023-04-27 14:30:17 -04:00
|
|
|
|
|
|
|
|
const changeHandler = e => {
|
|
|
|
|
setData({...data,[e.target.name]:[e.target.value]});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const submitHandler = e => {
|
|
|
|
|
e.preventDefault();
|
2023-04-29 12:01:45 -04:00
|
|
|
login();
|
2023-04-29 22:52:09 -04:00
|
|
|
|
2023-04-27 14:30:17 -04:00
|
|
|
}
|
2023-04-29 12:01:45 -04:00
|
|
|
|
2023-04-29 22:52:09 -04:00
|
|
|
const setSession = () => {
|
|
|
|
|
ReactSession.set("net_id", net_id[0]);
|
|
|
|
|
}
|
2023-04-29 12:01:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const getHello = () => {
|
|
|
|
|
Axios.get("http://3.219.93.142:8000/").then((response) => {
|
|
|
|
|
console.log(response.data);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const login = () => {
|
2023-04-29 16:15:28 -04:00
|
|
|
Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => {
|
|
|
|
|
console.log(response);
|
2023-04-29 22:52:09 -04:00
|
|
|
console.log(response.status);
|
|
|
|
|
if (response.status === 200){
|
|
|
|
|
setSession();
|
|
|
|
|
navigateHome();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-29 12:01:45 -04:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2023-04-29 16:15:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
<ThemeProvider theme={theme}>
|
2023-04-30 22:20:55 -04:00
|
|
|
<div className='bg' style={{backgroundImage: 'url(' + require('./images/back.jpg') + ')'}}>
|
2023-04-29 16:15:28 -04:00
|
|
|
<div className='logbox'>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
marginTop: 8,
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography component="h1" variant="h5">Log In</Typography>
|
2023-04-30 15:35:02 -04:00
|
|
|
<div className='logbox2'>
|
|
|
|
|
<Card sx={{ width:300, height:100 }}>
|
|
|
|
|
<CardMedia
|
|
|
|
|
component='Box'
|
|
|
|
|
image={ require("./images/logo.jpg")}
|
|
|
|
|
title="Logo"
|
|
|
|
|
sx={{ width: 300, height:100}}
|
|
|
|
|
alt="logo"
|
2023-04-30 14:42:40 -04:00
|
|
|
|
2023-04-30 15:35:02 -04:00
|
|
|
/>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
|
2023-04-29 16:15:28 -04:00
|
|
|
|
|
|
|
|
<form className='formbox' onSubmit={submitHandler}>
|
|
|
|
|
<TextField
|
|
|
|
|
margin="normal"
|
|
|
|
|
required
|
|
|
|
|
fullWidth
|
|
|
|
|
id="net_id"
|
|
|
|
|
label="net_id"
|
|
|
|
|
name="net_id"
|
|
|
|
|
autoComplete="net_id"
|
|
|
|
|
autoFocus
|
|
|
|
|
value={net_id}
|
|
|
|
|
onChange={changeHandler}
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
margin="normal"
|
|
|
|
|
required
|
|
|
|
|
fullWidth
|
|
|
|
|
id="password"
|
|
|
|
|
label="Password"
|
|
|
|
|
name="password"
|
|
|
|
|
autoComplete="password"
|
|
|
|
|
autoFocus
|
|
|
|
|
value={password}
|
|
|
|
|
onChange={changeHandler}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
fullWidth
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ mt: 3, mb: 2 }}
|
|
|
|
|
>
|
|
|
|
|
Sign In</Button>
|
2023-04-27 14:30:17 -04:00
|
|
|
</form>
|
2023-04-29 16:15:28 -04:00
|
|
|
<Button
|
|
|
|
|
onClick={navigateCreateAccount}
|
|
|
|
|
fullWidth
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{ mt: 3, mb: 2, width:1/4 }}
|
|
|
|
|
>Create Account</Button>
|
|
|
|
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
2023-04-27 14:30:17 -04:00
|
|
|
</div>
|
2023-04-29 16:15:28 -04:00
|
|
|
</div>
|
|
|
|
|
</ThemeProvider>
|
2023-04-27 14:30:17 -04:00
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Login;
|
2023-04-29 21:19:57 -04:00
|
|
|
|
|
|
|
|
|