blob: dd414d37b4aedfad155c7b7f42f735895b1bc50a [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';
simonfe1de722022-10-02 00:21:43 -04003import { FormEvent, 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
simonfe1de722022-10-02 00:21:43 -04007export default function ServerSetup() {
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
simonfe1de722022-10-02 00:21:43 -040014 const handleSubmit = (e: FormEvent) => {
simond47ef9e2022-09-28 22:24:28 -040015 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">
simonfe1de722022-10-02 00:21:43 -040023 <Card>
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 />
simon80b7b3b2022-09-28 17:50:10 -040031 Let&apos;s start by creating a new administrator account to control access to the server configuration.
Adrien Béraude74741b2021-04-19 13:22:54 -040032 </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"
simonfe1de722022-10-02 00:21:43 -040046 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040047 />
48 </div>
49 <div>
50 <Input
51 value={passwordRepeat}
52 onChange={(e) => setPasswordRepeat(e.target.value)}
53 name="password"
54 error={!!passwordRepeat && !isValid()}
55 type="password"
56 placeholder="Repeat password"
57 autoComplete="new-password"
simonfe1de722022-10-02 00:21:43 -040058 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040059 />
60 </div>
Adrien Béraud150b4782021-04-21 19:40:59 -040061 </Box>
62 <Box style={{ textAlign: 'center', marginTop: 24 }}>
simonfe1de722022-10-02 00:21:43 -040063 <Fab variant="extended" color="primary" type="submit" disabled={!isValid() || loading}>
simond47ef9e2022-09-28 22:24:28 -040064 <GroupAddRounded />
Adrien Béraude74741b2021-04-19 13:22:54 -040065 Create admin account
66 </Fab>
67 </Box>
68 </CardContent>
69 </Card>
simond47ef9e2022-09-28 22:24:28 -040070 </Container>
71 );
Adrien Béraude74741b2021-04-19 13:22:54 -040072}