fixed login redirect
This commit is contained in:
@@ -12,7 +12,7 @@ import Grid from '@material-ui/core/Grid';
|
||||
import Link1 from '@material-ui/core/Link';
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
const url = "/simcompanies/API/user/login"
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
card: {
|
||||
backgroundColor: "#0B1929",
|
||||
@@ -59,31 +59,32 @@ const CssTextField = withStyles({
|
||||
},
|
||||
})(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)
|
||||
});
|
||||
|
||||
if (response.status == "200") {
|
||||
return <Redirect to={"/"} />
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default function Login() {
|
||||
const classes = useStyles();
|
||||
|
||||
const url = "/simcompanies/API/user/login"
|
||||
const [username, setUsername] = React.useState("");
|
||||
const [password, setPassword] = React.useState("");
|
||||
const [login, setLogin] = React.useState(true);
|
||||
|
||||
|
||||
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)
|
||||
});
|
||||
|
||||
if (response.status == "200") {
|
||||
setLogin(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClick = (e) => {
|
||||
|
||||
@@ -100,71 +101,75 @@ export default function Login() {
|
||||
const handleChangePW = (e) => {
|
||||
setPassword(e.target.value)
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||
<Card className={classes.card} raised>
|
||||
<CardContent>
|
||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||
<img src={Logo} alt="SC Dashboard Logo" className={classes.logo} />
|
||||
</Box >
|
||||
<form>
|
||||
|
||||
login === true ?
|
||||
< Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||
<Card className={classes.card} raised>
|
||||
<CardContent>
|
||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||
<Grid container spacing={2} >
|
||||
<Grid item xs={12} >
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Typography variant="h4" color="secondary">
|
||||
Login
|
||||
</Typography>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12} >
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<CssTextField
|
||||
id="usernameInput"
|
||||
label="Username"
|
||||
variant="outlined"
|
||||
value={username}
|
||||
onChange={handleChangeUSR}
|
||||
className={classes.input}
|
||||
/>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<CssTextField
|
||||
id="passwordInput"
|
||||
type="password"
|
||||
label="Password"
|
||||
autoComplete="current-password"
|
||||
variant="outlined"
|
||||
value={password}
|
||||
onChange={handleChangePW}
|
||||
className={classes.input}
|
||||
/>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Typography variant="subtitle2" >
|
||||
<Link1 to="/login/createuser" component={Link} color="secondary">
|
||||
Create new Account
|
||||
</Link1>
|
||||
</Typography>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Button variant="contained" color="secondary" onClick={handleClick}>
|
||||
Login
|
||||
</Button>
|
||||
</Box >
|
||||
</Grid>
|
||||
</Grid>
|
||||
<img src={Logo} alt="SC Dashboard Logo" className={classes.logo} />
|
||||
</Box >
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Box >
|
||||
<form>
|
||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||
<Grid container spacing={2} >
|
||||
<Grid item xs={12} >
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Typography variant="h4" color="secondary">
|
||||
Login
|
||||
</Typography>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12} >
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<CssTextField
|
||||
id="usernameInput"
|
||||
label="Username"
|
||||
variant="outlined"
|
||||
value={username}
|
||||
onChange={handleChangeUSR}
|
||||
className={classes.input}
|
||||
/>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<CssTextField
|
||||
id="passwordInput"
|
||||
type="password"
|
||||
label="Password"
|
||||
autoComplete="current-password"
|
||||
variant="outlined"
|
||||
value={password}
|
||||
onChange={handleChangePW}
|
||||
className={classes.input}
|
||||
/>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Typography variant="subtitle2" >
|
||||
<Link1 to="/login/createuser" component={Link} color="secondary">
|
||||
Create new Account
|
||||
</Link1>
|
||||
</Typography>
|
||||
</Box >
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Box display="flex" justifyContent="center" >
|
||||
<Button variant="contained" color="secondary" onClick={handleClick}>
|
||||
Login
|
||||
</Button>
|
||||
</Box >
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box >
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Box > : <Redirect to='/' />
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user