simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 18 | import GroupAddRounded from '@mui/icons-material/GroupAddRounded'; |
| 19 | import { Box, Card, CardContent, Container, Fab, Input, Typography } from '@mui/material'; |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 20 | import { FormEvent, useState } from 'react'; |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 21 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 22 | import authManager from '../AuthManager'; |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 23 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 24 | export default function ServerSetup() { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 25 | const [password, setPassword] = useState(''); |
| 26 | const [passwordRepeat, setPasswordRepeat] = useState(''); |
| 27 | const [loading, setLoading] = useState(false); |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 28 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | const isValid = () => password && password === passwordRepeat; |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 30 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 31 | const handleSubmit = (e: FormEvent) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 32 | e.preventDefault(); |
| 33 | setLoading(true); |
| 34 | if (!isValid()) return; |
| 35 | authManager.setup(password); |
| 36 | }; |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 37 | |
| 38 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 39 | <Container className="message-list"> |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 40 | <Card> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 41 | <CardContent component="form" onSubmit={handleSubmit}> |
| 42 | <Typography gutterBottom variant="h5" component="h2"> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | Jami Web Node setup |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 44 | </Typography> |
| 45 | <Typography variant="body2" color="textSecondary" component="p"> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 46 | Welcome to the Jami web node setup. |
| 47 | <br /> |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 48 | Let's start by creating a new administrator account to control access to the server configuration. |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 49 | </Typography> |
| 50 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 51 | <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 52 | <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" |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 63 | disabled={loading} |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 64 | /> |
| 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" |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 75 | disabled={loading} |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 76 | /> |
| 77 | </div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 78 | </Box> |
| 79 | <Box style={{ textAlign: 'center', marginTop: 24 }}> |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 80 | <Fab variant="extended" color="primary" type="submit" disabled={!isValid() || loading}> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 81 | <GroupAddRounded /> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 82 | Create admin account |
| 83 | </Fab> |
| 84 | </Box> |
| 85 | </CardContent> |
| 86 | </Card> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 87 | </Container> |
| 88 | ); |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 89 | } |