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