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 Link1 from '@material-ui/core/Link';
|
||||||
import { Redirect } from "react-router-dom";
|
import { Redirect } from "react-router-dom";
|
||||||
|
|
||||||
const url = "/simcompanies/API/user/login"
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
card: {
|
card: {
|
||||||
backgroundColor: "#0B1929",
|
backgroundColor: "#0B1929",
|
||||||
@@ -59,31 +59,32 @@ 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)
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status == "200") {
|
|
||||||
return <Redirect to={"/"} />
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const url = "/simcompanies/API/user/login"
|
||||||
const [username, setUsername] = React.useState("");
|
const [username, setUsername] = React.useState("");
|
||||||
const [password, setPassword] = 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) => {
|
const handleClick = (e) => {
|
||||||
|
|
||||||
@@ -100,71 +101,75 @@ export default function Login() {
|
|||||||
const handleChangePW = (e) => {
|
const handleChangePW = (e) => {
|
||||||
setPassword(e.target.value)
|
setPassword(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
|
||||||
<Card className={classes.card} raised>
|
login === true ?
|
||||||
<CardContent>
|
< Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
<Card className={classes.card} raised>
|
||||||
<img src={Logo} alt="SC Dashboard Logo" className={classes.logo} />
|
<CardContent>
|
||||||
</Box >
|
|
||||||
<form>
|
|
||||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||||
<Grid container spacing={2} >
|
<img src={Logo} alt="SC Dashboard Logo" className={classes.logo} />
|
||||||
<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 >
|
</Box >
|
||||||
</form>
|
<form>
|
||||||
</CardContent>
|
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||||
</Card>
|
<Grid container spacing={2} >
|
||||||
</Box >
|
<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