Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 1 | import React, { useState } from 'react' |
| 2 | import { useHistory } from "react-router-dom" |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 3 | |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 4 | import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@material-ui/core' |
| 5 | import GroupAddRounded from '@material-ui/icons/GroupAddRounded' |
| 6 | import { makeStyles } from '@material-ui/core/styles' |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 7 | import authManager from '../AuthManager' |
| 8 | |
| 9 | const useStyles = makeStyles((theme) => ({ |
| 10 | root: { |
| 11 | '& > *': { |
| 12 | margin: theme.spacing(1), |
| 13 | }, |
| 14 | }, |
| 15 | extendedIcon: { |
| 16 | marginRight: theme.spacing(1), |
| 17 | }, |
| 18 | wizardCard: { |
| 19 | borderRadius: 8, |
| 20 | maxWidth: 360, |
| 21 | margin: "16px auto" |
| 22 | }, textField: { |
| 23 | margin: theme.spacing(1), |
| 24 | } |
| 25 | })) |
| 26 | |
| 27 | export default function ServerSetup(props) { |
| 28 | const classes = useStyles() |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 29 | const history = useHistory() |
| 30 | const [password, setPassword] = useState('') |
| 31 | const [passwordRepeat, setPasswordRepeat] = useState('') |
| 32 | const [loading, setLoading] = useState(false) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 33 | |
| 34 | const isValid = () => password && password === passwordRepeat |
| 35 | |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 36 | const handleSubmit = e => { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 37 | e.preventDefault() |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 38 | setLoading(true) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 39 | if (!isValid()) |
| 40 | return |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 41 | authManager.setup(password) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | return ( |
| 45 | <Container className='message-list'> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 46 | <Card className={classes.wizardCard} disabled={loading}> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 47 | <CardContent component="form" onSubmit={handleSubmit}> |
| 48 | <Typography gutterBottom variant="h5" component="h2"> |
| 49 | Jami Web Node setup |
| 50 | </Typography> |
| 51 | <Typography variant="body2" color="textSecondary" component="p"> |
| 52 | Welcome to the Jami web node setup.<br/> |
| 53 | Let's start by creating a new administrator account to control access to the server configuration. |
| 54 | </Typography> |
| 55 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 56 | <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 57 | <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div> |
| 58 | <div><Input |
| 59 | className={classes.textField} |
| 60 | value={password} |
| 61 | onChange={e => setPassword(e.target.value)} |
| 62 | name="password" |
| 63 | type='password' |
| 64 | placeholder="New password" |
| 65 | autoComplete="new-password" /> |
| 66 | </div> |
| 67 | <div><Input |
| 68 | className={classes.textField} |
| 69 | value={passwordRepeat} |
| 70 | onChange={e => setPasswordRepeat(e.target.value)} |
| 71 | name="password" |
| 72 | error={!!passwordRepeat && !isValid()} |
| 73 | type='password' |
| 74 | placeholder="Repeat password" |
| 75 | autoComplete="new-password" /></div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 76 | </Box> |
| 77 | <Box style={{ textAlign: 'center', marginTop: 24 }}> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 78 | <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}> |
| 79 | <GroupAddRounded className={classes.extendedIcon} /> |
| 80 | Create admin account |
| 81 | </Fab> |
| 82 | </Box> |
| 83 | </CardContent> |
| 84 | </Card> |
| 85 | </Container>) |
| 86 | } |