fixed redirect

This commit is contained in:
2020-04-25 02:28:55 +02:00
parent 55e693b38d
commit bbb5b7e3c0

View File

@@ -59,29 +59,32 @@ const CssTextField = withStyles({
},
})(TextField);
const putCreateAccount = async (url, data) => {
const response = await fetch(url, {
method: 'PUT',
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={"/login"} />
}
}
export default function CreateAccount() {
const classes = useStyles();
const [username, setUsername] = React.useState("");
const [password, setPassword] = React.useState("");
const [login, setLogin] = React.useState(true);
const putCreateAccount = async (url, data) => {
const response = await fetch(url, {
method: 'PUT',
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) => {
if (username !== "" && password !== "") {
@@ -99,61 +102,62 @@ export default function CreateAccount() {
}
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">
Create new Account
</Typography>
</Box >
</Grid>
<Grid item xs={12} >
<Box display="flex" justifyContent="center" >
<CssTextField
id="usernameInput"
label="Username"
variant="outlined"
onChange={handleChangeUSR}
value={username}
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" >
<Button variant="contained" color="secondary" onClick={handleClick}>
Create Account
</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">
Create new Account
</Typography>
</Box >
</Grid>
<Grid item xs={12} >
<Box display="flex" justifyContent="center" >
<CssTextField
id="usernameInput"
label="Username"
variant="outlined"
onChange={handleChangeUSR}
value={username}
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" >
<Button variant="contained" color="secondary" onClick={handleClick}>
Create Account
</Button>
</Box >
</Grid>
</Grid>
</Box >
</form>
</CardContent>
</Card>
</Box > : <Redirect to={"/login"} />
)
}