blob: e0457511fb205427ee706986455cedc495cfde64 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simon07b4eb02022-09-29 17:50:26 -040018import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
19import { Box, Card, CardContent, Container, Fab, Input, Typography } from '@mui/material';
simonfe1de722022-10-02 00:21:43 -040020import { FormEvent, useState } from 'react';
Adrien Béraude74741b2021-04-19 13:22:54 -040021
simond47ef9e2022-09-28 22:24:28 -040022import authManager from '../AuthManager';
Adrien Béraude74741b2021-04-19 13:22:54 -040023
simonfe1de722022-10-02 00:21:43 -040024export default function ServerSetup() {
simond47ef9e2022-09-28 22:24:28 -040025 const [password, setPassword] = useState('');
26 const [passwordRepeat, setPasswordRepeat] = useState('');
27 const [loading, setLoading] = useState(false);
Adrien Béraude74741b2021-04-19 13:22:54 -040028
simond47ef9e2022-09-28 22:24:28 -040029 const isValid = () => password && password === passwordRepeat;
Adrien Béraude74741b2021-04-19 13:22:54 -040030
simonfe1de722022-10-02 00:21:43 -040031 const handleSubmit = (e: FormEvent) => {
simond47ef9e2022-09-28 22:24:28 -040032 e.preventDefault();
33 setLoading(true);
34 if (!isValid()) return;
35 authManager.setup(password);
36 };
Adrien Béraude74741b2021-04-19 13:22:54 -040037
38 return (
simond47ef9e2022-09-28 22:24:28 -040039 <Container className="message-list">
simonfe1de722022-10-02 00:21:43 -040040 <Card>
Adrien Béraude74741b2021-04-19 13:22:54 -040041 <CardContent component="form" onSubmit={handleSubmit}>
42 <Typography gutterBottom variant="h5" component="h2">
simond47ef9e2022-09-28 22:24:28 -040043 Jami Web Node setup
Adrien Béraude74741b2021-04-19 13:22:54 -040044 </Typography>
45 <Typography variant="body2" color="textSecondary" component="p">
simond47ef9e2022-09-28 22:24:28 -040046 Welcome to the Jami web node setup.
47 <br />
simon80b7b3b2022-09-28 17:50:10 -040048 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 -040049 </Typography>
50
Adrien Béraud150b4782021-04-21 19:40:59 -040051 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
simond47ef9e2022-09-28 22:24:28 -040052 <div>
53 <Input value="admin" name="username" autoComplete="username" disabled />
54 </div>
55 <div>
56 <Input
57 value={password}
58 onChange={(e) => setPassword(e.target.value)}
59 name="password"
60 type="password"
61 placeholder="New password"
62 autoComplete="new-password"
simonfe1de722022-10-02 00:21:43 -040063 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040064 />
65 </div>
66 <div>
67 <Input
68 value={passwordRepeat}
69 onChange={(e) => setPasswordRepeat(e.target.value)}
70 name="password"
71 error={!!passwordRepeat && !isValid()}
72 type="password"
73 placeholder="Repeat password"
74 autoComplete="new-password"
simonfe1de722022-10-02 00:21:43 -040075 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040076 />
77 </div>
Adrien Béraud150b4782021-04-21 19:40:59 -040078 </Box>
79 <Box style={{ textAlign: 'center', marginTop: 24 }}>
simonfe1de722022-10-02 00:21:43 -040080 <Fab variant="extended" color="primary" type="submit" disabled={!isValid() || loading}>
simond47ef9e2022-09-28 22:24:28 -040081 <GroupAddRounded />
Adrien Béraude74741b2021-04-19 13:22:54 -040082 Create admin account
83 </Fab>
84 </Box>
85 </CardContent>
86 </Card>
simond47ef9e2022-09-28 22:24:28 -040087 </Container>
88 );
Adrien Béraude74741b2021-04-19 13:22:54 -040089}