fixed redirect
This commit is contained in:
@@ -59,29 +59,32 @@ const CssTextField = withStyles({
|
|||||||
},
|
},
|
||||||
})(TextField);
|
})(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() {
|
export default function CreateAccount() {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
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 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) => {
|
const handleClick = (e) => {
|
||||||
|
|
||||||
if (username !== "" && password !== "") {
|
if (username !== "" && password !== "") {
|
||||||
@@ -99,61 +102,62 @@ export default function CreateAccount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
login === true ?
|
||||||
<Card className={classes.card} raised>
|
<Box className="loginBackground" display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
||||||
<CardContent>
|
<Card className={classes.card} raised>
|
||||||
<Box display="flex" justifyContent="center" alignItems="center" m={1} p={1} >
|
<CardContent>
|
||||||
<img src={Logo} alt="SC Dashboard Logo" className={classes.logo} />
|
|
||||||
</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">
|
|
||||||
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 >
|
</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">
|
||||||
|
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"} />
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user