added post login
This commit is contained in:
@@ -117,6 +117,7 @@ export default function CreateAccount() {
|
|||||||
label="Username"
|
label="Username"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={handleChangeUSR}
|
onChange={handleChangeUSR}
|
||||||
|
value={username}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
@@ -129,6 +130,7 @@ export default function CreateAccount() {
|
|||||||
label="Password"
|
label="Password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
value={password}
|
||||||
onChange={handleChangePW}
|
onChange={handleChangePW}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ import Logo from "../../img/logo.png";
|
|||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
import Grid from '@material-ui/core/Grid';
|
import Grid from '@material-ui/core/Grid';
|
||||||
import Link1 from '@material-ui/core/Link';
|
import Link1 from '@material-ui/core/Link';
|
||||||
import CreateAccount from './createAccount';
|
|
||||||
|
|
||||||
|
|
||||||
|
const url = "/simcompanies/API/user/login"
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
card: {
|
card: {
|
||||||
backgroundColor: "#0B1929",
|
backgroundColor: "#0B1929",
|
||||||
@@ -59,8 +58,51 @@ const CssTextField = withStyles({
|
|||||||
},
|
},
|
||||||
})(TextField);
|
})(TextField);
|
||||||
|
|
||||||
|
const postLogin = async (url, data) => {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'cors',
|
||||||
|
cache: 'no-cache',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
redirect: 'follow',
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkLogin = async (url) => {
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (response.status == "200") {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
|
const [username, setUsername] = React.useState("");
|
||||||
|
const [password, setPassword] = React.useState("");
|
||||||
|
|
||||||
|
const handleClick = (e) => {
|
||||||
|
|
||||||
|
if (username !== "" && password !== "") {
|
||||||
|
postLogin(url, { email: username, password: password })
|
||||||
|
|
||||||
|
setUsername("")
|
||||||
|
setPassword("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const handleChangeUSR = (e) => {
|
||||||
|
setUsername(e.target.value)
|
||||||
|
}
|
||||||
|
const handleChangePW = (e) => {
|
||||||
|
setPassword(e.target.value)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||||
<Card className={classes.card} raised>
|
<Card className={classes.card} raised>
|
||||||
@@ -84,6 +126,7 @@ export default function Login() {
|
|||||||
id="usernameInput"
|
id="usernameInput"
|
||||||
label="Username"
|
label="Username"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
onChange={handleChangeUSR}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
@@ -96,6 +139,7 @@ export default function Login() {
|
|||||||
label="Password"
|
label="Password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
onChange={handleChangePW}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
@@ -111,7 +155,7 @@ export default function Login() {
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
<Box display="flex" justifyContent="center" >
|
<Box display="flex" justifyContent="center" >
|
||||||
<Button variant="contained" color="secondary">
|
<Button variant="contained" color="secondary" onClick={handleClick}>
|
||||||
Login
|
Login
|
||||||
</Button>
|
</Button>
|
||||||
</Box >
|
</Box >
|
||||||
|
|||||||
Reference in New Issue
Block a user