blob: 95fc032e71348bce526fbe861cbcce6c7cfaa14f [file] [log] [blame]
simon07b4eb02022-09-29 17:50:26 -04001import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
2import { Box, Card, CardContent, Container, Fab, Input, Typography } from '@mui/material';
simond47ef9e2022-09-28 22:24:28 -04003import { useState } from 'react';
Adrien Béraude74741b2021-04-19 13:22:54 -04004
simond47ef9e2022-09-28 22:24:28 -04005import authManager from '../AuthManager';
Adrien Béraude74741b2021-04-19 13:22:54 -04006
Adrien Béraude74741b2021-04-19 13:22:54 -04007export default function ServerSetup(props) {
simond47ef9e2022-09-28 22:24:28 -04008 const [password, setPassword] = useState('');
9 const [passwordRepeat, setPasswordRepeat] = useState('');
10 const [loading, setLoading] = useState(false);
Adrien Béraude74741b2021-04-19 13:22:54 -040011
simond47ef9e2022-09-28 22:24:28 -040012 const isValid = () => password && password === passwordRepeat;
Adrien Béraude74741b2021-04-19 13:22:54 -040013
simond47ef9e2022-09-28 22:24:28 -040014 const handleSubmit = (e) => {
15 e.preventDefault();
16 setLoading(true);
17 if (!isValid()) return;
18 authManager.setup(password);
19 };
Adrien Béraude74741b2021-04-19 13:22:54 -040020
21 return (
simond47ef9e2022-09-28 22:24:28 -040022 <Container className="message-list">
idillonfb2af5b2022-09-16 13:40:08 -040023 <Card disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040024 <CardContent component="form" onSubmit={handleSubmit}>
25 <Typography gutterBottom variant="h5" component="h2">
simond47ef9e2022-09-28 22:24:28 -040026 Jami Web Node setup
Adrien Béraude74741b2021-04-19 13:22:54 -040027 </Typography>
28 <Typography variant="body2" color="textSecondary" component="p">
simond47ef9e2022-09-28 22:24:28 -040029 Welcome to the Jami web node setup.
30 <br />
Adrien Béraude74741b2021-04-19 13:22:54 -040031 Let's start by creating a new administrator account to control access to the server configuration.
32 </Typography>
33
Adrien Béraud150b4782021-04-21 19:40:59 -040034 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
simond47ef9e2022-09-28 22:24:28 -040035 <div>
36 <Input value="admin" name="username" autoComplete="username" disabled />
37 </div>
38 <div>
39 <Input
40 value={password}
41 onChange={(e) => setPassword(e.target.value)}
42 name="password"
43 type="password"
44 placeholder="New password"
45 autoComplete="new-password"
46 />
47 </div>
48 <div>
49 <Input
50 value={passwordRepeat}
51 onChange={(e) => setPasswordRepeat(e.target.value)}
52 name="password"
53 error={!!passwordRepeat && !isValid()}
54 type="password"
55 placeholder="Repeat password"
56 autoComplete="new-password"
57 />
58 </div>
Adrien Béraud150b4782021-04-21 19:40:59 -040059 </Box>
60 <Box style={{ textAlign: 'center', marginTop: 24 }}>
simond47ef9e2022-09-28 22:24:28 -040061 <Fab variant="extended" color="primary" type="submit" disabled={!isValid()}>
62 <GroupAddRounded />
Adrien Béraude74741b2021-04-19 13:22:54 -040063 Create admin account
64 </Fab>
65 </Box>
66 </CardContent>
67 </Card>
simond47ef9e2022-09-28 22:24:28 -040068 </Container>
69 );
Adrien Béraude74741b2021-04-19 13:22:54 -040070}