blob: e6ff0aaf273e027b0b690fec7d1daf75b7e4db83 [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
simonfe1de722022-10-02 00:21:43 -040022export default function ServerSetup() {
simond47ef9e2022-09-28 22:24:28 -040023 const [password, setPassword] = useState('');
24 const [passwordRepeat, setPasswordRepeat] = useState('');
25 const [loading, setLoading] = useState(false);
Adrien Béraude74741b2021-04-19 13:22:54 -040026
simond47ef9e2022-09-28 22:24:28 -040027 const isValid = () => password && password === passwordRepeat;
Adrien Béraude74741b2021-04-19 13:22:54 -040028
simonfe1de722022-10-02 00:21:43 -040029 const handleSubmit = (e: FormEvent) => {
simond47ef9e2022-09-28 22:24:28 -040030 e.preventDefault();
31 setLoading(true);
32 if (!isValid()) return;
simon5da8ca62022-11-09 15:21:25 -050033 // TODO: Migrate to new server
34 // authManager.setup(password);
simond47ef9e2022-09-28 22:24:28 -040035 };
Adrien Béraude74741b2021-04-19 13:22:54 -040036
37 return (
simond47ef9e2022-09-28 22:24:28 -040038 <Container className="message-list">
simonfe1de722022-10-02 00:21:43 -040039 <Card>
Adrien Béraude74741b2021-04-19 13:22:54 -040040 <CardContent component="form" onSubmit={handleSubmit}>
41 <Typography gutterBottom variant="h5" component="h2">
simond47ef9e2022-09-28 22:24:28 -040042 Jami Web Node setup
Adrien Béraude74741b2021-04-19 13:22:54 -040043 </Typography>
44 <Typography variant="body2" color="textSecondary" component="p">
simond47ef9e2022-09-28 22:24:28 -040045 Welcome to the Jami web node setup.
46 <br />
simon80b7b3b2022-09-28 17:50:10 -040047 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 -040048 </Typography>
49
Adrien Béraud150b4782021-04-21 19:40:59 -040050 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
simond47ef9e2022-09-28 22:24:28 -040051 <div>
52 <Input value="admin" name="username" autoComplete="username" disabled />
53 </div>
54 <div>
55 <Input
56 value={password}
57 onChange={(e) => setPassword(e.target.value)}
58 name="password"
59 type="password"
60 placeholder="New password"
61 autoComplete="new-password"
simonfe1de722022-10-02 00:21:43 -040062 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040063 />
64 </div>
65 <div>
66 <Input
67 value={passwordRepeat}
68 onChange={(e) => setPasswordRepeat(e.target.value)}
69 name="password"
70 error={!!passwordRepeat && !isValid()}
71 type="password"
72 placeholder="Repeat password"
73 autoComplete="new-password"
simonfe1de722022-10-02 00:21:43 -040074 disabled={loading}
simond47ef9e2022-09-28 22:24:28 -040075 />
76 </div>
Adrien Béraud150b4782021-04-21 19:40:59 -040077 </Box>
78 <Box style={{ textAlign: 'center', marginTop: 24 }}>
simonfe1de722022-10-02 00:21:43 -040079 <Fab variant="extended" color="primary" type="submit" disabled={!isValid() || loading}>
simond47ef9e2022-09-28 22:24:28 -040080 <GroupAddRounded />
Adrien Béraude74741b2021-04-19 13:22:54 -040081 Create admin account
82 </Fab>
83 </Box>
84 </CardContent>
85 </Card>
simond47ef9e2022-09-28 22:24:28 -040086 </Container>
87 );
Adrien Béraude74741b2021-04-19 13:22:54 -040088}