Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 1 | import { 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' |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 5 | import authManager from '../AuthManager' |
| 6 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 7 | export default function ServerSetup(props) { |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 8 | const [password, setPassword] = useState('') |
| 9 | const [passwordRepeat, setPasswordRepeat] = useState('') |
| 10 | const [loading, setLoading] = useState(false) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 11 | |
| 12 | const isValid = () => password && password === passwordRepeat |
| 13 | |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 14 | const handleSubmit = e => { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 15 | e.preventDefault() |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 16 | setLoading(true) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 17 | if (!isValid()) |
| 18 | return |
Adrien Béraud | e5cad98 | 2021-06-07 10:05:50 -0400 | [diff] [blame] | 19 | authManager.setup(password) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | return ( |
| 23 | <Container className='message-list'> |
idillon | fb2af5b | 2022-09-16 13:40:08 -0400 | [diff] [blame] | 24 | <Card disabled={loading}> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 25 | <CardContent component="form" onSubmit={handleSubmit}> |
| 26 | <Typography gutterBottom variant="h5" component="h2"> |
| 27 | Jami Web Node setup |
| 28 | </Typography> |
| 29 | <Typography variant="body2" color="textSecondary" component="p"> |
| 30 | Welcome to the Jami web node setup.<br/> |
| 31 | Let's start by creating a new administrator account to control access to the server configuration. |
| 32 | </Typography> |
| 33 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 34 | <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}> |
idillon | fb2af5b | 2022-09-16 13:40:08 -0400 | [diff] [blame] | 35 | <div><Input value="admin" name="username" autoComplete="username" disabled /></div> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 36 | <div><Input |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 37 | value={password} |
| 38 | onChange={e => setPassword(e.target.value)} |
| 39 | name="password" |
| 40 | type='password' |
| 41 | placeholder="New password" |
| 42 | autoComplete="new-password" /> |
| 43 | </div> |
| 44 | <div><Input |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 45 | value={passwordRepeat} |
| 46 | onChange={e => setPasswordRepeat(e.target.value)} |
| 47 | name="password" |
| 48 | error={!!passwordRepeat && !isValid()} |
| 49 | type='password' |
| 50 | placeholder="Repeat password" |
| 51 | autoComplete="new-password" /></div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 52 | </Box> |
| 53 | <Box style={{ textAlign: 'center', marginTop: 24 }}> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 54 | <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}> |
idillon | fb2af5b | 2022-09-16 13:40:08 -0400 | [diff] [blame] | 55 | <GroupAddRounded/> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 56 | Create admin account |
| 57 | </Fab> |
| 58 | </Box> |
| 59 | </CardContent> |
| 60 | </Card> |
| 61 | </Container>) |
| 62 | } |