blob: 70f9342dedc8a5242475024bcd9a2a50efb657d9 [file] [log] [blame]
Adrien BĂ©raude74741b2021-04-19 13:22:54 -04001import React, { useState } from 'react';
2import { useHistory } from "react-router-dom";
3
4import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@material-ui/core';
5import GroupAddRounded from '@material-ui/icons/GroupAddRounded';
6import { makeStyles } from '@material-ui/core/styles';
7import authManager from '../AuthManager'
8
9const useStyles = makeStyles((theme) => ({
10 root: {
11 '& > *': {
12 margin: theme.spacing(1),
13 },
14 },
15 extendedIcon: {
16 marginRight: theme.spacing(1),
17 },
18 wizardCard: {
19 borderRadius: 8,
20 maxWidth: 360,
21 margin: "16px auto"
22 }, textField: {
23 margin: theme.spacing(1),
24 }
25}))
26
27export default function ServerSetup(props) {
28 const classes = useStyles()
29 const history = useHistory();
30 const [password, setPassword] = useState('');
31 const [passwordRepeat, setPasswordRepeat] = useState('');
32
33 const isValid = () => password && password === passwordRepeat
34
35 const handleSubmit = async e => {
36 e.preventDefault()
37 if (!isValid())
38 return
39 if (await authManager.setup(password)) {
40 history.replace('/')
41 }
42 }
43
44 return (
45 <Container className='message-list'>
46 <Card className={classes.wizardCard}>
47 <CardContent component="form" onSubmit={handleSubmit}>
48 <Typography gutterBottom variant="h5" component="h2">
49 Jami Web Node setup
50 </Typography>
51 <Typography variant="body2" color="textSecondary" component="p">
52 Welcome to the Jami web node setup.<br/>
53 Let's start by creating a new administrator account to control access to the server configuration.
54 </Typography>
55
56 <Typography variant='body1'></Typography>
57 <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div>
58 <div><Input
59 className={classes.textField}
60 value={password}
61 onChange={e => setPassword(e.target.value)}
62 name="password"
63 type='password'
64 placeholder="New password"
65 autoComplete="new-password" />
66 </div>
67 <div><Input
68 className={classes.textField}
69 value={passwordRepeat}
70 onChange={e => setPasswordRepeat(e.target.value)}
71 name="password"
72 error={!!passwordRepeat && !isValid()}
73 type='password'
74 placeholder="Repeat password"
75 autoComplete="new-password" /></div>
76 <Box style={{ textAlign: 'center', marginTop: 16 }}>
77 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
78 <GroupAddRounded className={classes.extendedIcon} />
79 Create admin account
80 </Fab>
81 </Box>
82 </CardContent>
83 </Card>
84 </Container>)
85}