blob: e2722fdd0d73dbd191a9efa737010f4a7860968e [file] [log] [blame]
Adrien Béraude5cad982021-06-07 10:05:50 -04001import React, { useState } from 'react'
Adrien Béraude74741b2021-04-19 13:22:54 -04002
Adrien Béraudab519ff2022-05-03 15:34:48 -04003import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@mui/material'
4import GroupAddRounded from '@mui/icons-material/GroupAddRounded'
Adrien Béraude74741b2021-04-19 13:22:54 -04005import authManager from '../AuthManager'
6
Adrien Béraude74741b2021-04-19 13:22:54 -04007export default function ServerSetup(props) {
Adrien Béraude5cad982021-06-07 10:05:50 -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
12 const isValid = () => password && password === passwordRepeat
13
Adrien Béraude5cad982021-06-07 10:05:50 -040014 const handleSubmit = e => {
Adrien Béraude74741b2021-04-19 13:22:54 -040015 e.preventDefault()
Adrien Béraud150b4782021-04-21 19:40:59 -040016 setLoading(true)
Adrien Béraude74741b2021-04-19 13:22:54 -040017 if (!isValid())
18 return
Adrien Béraude5cad982021-06-07 10:05:50 -040019 authManager.setup(password)
Adrien Béraude74741b2021-04-19 13:22:54 -040020 }
21
22 return (
23 <Container className='message-list'>
idillonfb2af5b2022-09-16 13:40:08 -040024 <Card disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040025 <CardContent component="form" onSubmit={handleSubmit}>
26 <Typography gutterBottom variant="h5" component="h2">
27 Jami Web Node setup
28 </Typography>
29 <Typography variant="body2" color="textSecondary" component="p">
30 Welcome to the Jami web node setup.<br/>
31 Let's start by creating a new administrator account to control access to the server configuration.
32 </Typography>
33
Adrien Béraud150b4782021-04-21 19:40:59 -040034 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
idillonfb2af5b2022-09-16 13:40:08 -040035 <div><Input value="admin" name="username" autoComplete="username" disabled /></div>
Adrien Béraude74741b2021-04-19 13:22:54 -040036 <div><Input
Adrien Béraude74741b2021-04-19 13:22:54 -040037 value={password}
38 onChange={e => setPassword(e.target.value)}
39 name="password"
40 type='password'
41 placeholder="New password"
42 autoComplete="new-password" />
43 </div>
44 <div><Input
Adrien Béraude74741b2021-04-19 13:22:54 -040045 value={passwordRepeat}
46 onChange={e => setPasswordRepeat(e.target.value)}
47 name="password"
48 error={!!passwordRepeat && !isValid()}
49 type='password'
50 placeholder="Repeat password"
51 autoComplete="new-password" /></div>
Adrien Béraud150b4782021-04-21 19:40:59 -040052 </Box>
53 <Box style={{ textAlign: 'center', marginTop: 24 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040054 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
idillonfb2af5b2022-09-16 13:40:08 -040055 <GroupAddRounded/>
Adrien Béraude74741b2021-04-19 13:22:54 -040056 Create admin account
57 </Fab>
58 </Box>
59 </CardContent>
60 </Card>
61 </Container>)
62}