@mblaney/holster-browser 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -3
- package/package.json +1 -1
- package/src/components/Login.jsx +56 -80
- package/src/components/LoginCodes.jsx +1 -5
- package/src/components/Register.jsx +64 -86
- package/src/components/RequestCode.jsx +27 -41
- package/src/components/ResetPassword.jsx +34 -52
- package/src/components/Settings.jsx +5 -7
- package/src/components/Signup.jsx +138 -0
- package/src/components/UpdatePassword.jsx +44 -75
- package/src/components/ValidateEmail.jsx +10 -22
- package/src/components/__tests__/Signup.test.jsx +183 -0
- package/src/hooks/useAccountSync.js +110 -0
- package/src/index.js +2 -1
- package/src/utils/serviceWorkerRegistration.js +0 -88
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Peer dependencies: `@mblaney/holster`, `@mui/material`, `@mui/icons-material`, `
|
|
|
14
14
|
import {
|
|
15
15
|
Login,
|
|
16
16
|
Register,
|
|
17
|
+
Signup,
|
|
17
18
|
RequestCode,
|
|
18
19
|
ValidateEmail,
|
|
19
20
|
ResetPassword,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
LoginCodes,
|
|
23
24
|
EditCache,
|
|
24
25
|
SearchAppBar,
|
|
25
|
-
|
|
26
|
+
useAccountSync,
|
|
26
27
|
} from "@mblaney/holster-browser"
|
|
27
28
|
```
|
|
28
29
|
|
|
@@ -57,14 +58,59 @@ const appBar = {
|
|
|
57
58
|
|
|
58
59
|
#### Auth components
|
|
59
60
|
|
|
60
|
-
`Login`, `Register`, `RequestCode`, `ValidateEmail`, `ResetPassword`, and `UpdatePassword`
|
|
61
|
+
`Login`, `Register`, `Signup`, `RequestCode`, `ValidateEmail`, `ResetPassword`, and `UpdatePassword` render only their own form content (fields, submit button, status message) — no page container, card, or app bar. This keeps holster-browser out of the business of page layout, so each app is free to wrap them however it likes, including its own home nav or logo.
|
|
62
|
+
|
|
63
|
+
`Register` needs the login code supplied up front (obtained via the waitlist flow or shared directly). `Signup` instead has the server assign a login code automatically from a pool (see the `signup` option in [holster-router](https://github.com/mblaney/holster-router)); the code isn't provided by the client, it's sent back in the sign up email that also asks the user to validate their address.
|
|
64
|
+
|
|
65
|
+
Each component's props:
|
|
66
|
+
|
|
67
|
+
| Component | Props |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `Login` | `user`, `host` |
|
|
70
|
+
| `Register` | `user` |
|
|
71
|
+
| `Signup` | `user` |
|
|
72
|
+
| `RequestCode` | *(none)* |
|
|
73
|
+
| `ValidateEmail` | `code`, `validate` |
|
|
74
|
+
| `ResetPassword` | `loggedIn` |
|
|
75
|
+
| `UpdatePassword` | `user`, `loggedIn`, `current`, `code`, `reset` |
|
|
76
|
+
|
|
77
|
+
`ValidateEmail`'s `code`/`validate` and `UpdatePassword`'s `current`/`code`/`reset` come from the query params on the links in the sign up and reset-password emails respectively.
|
|
78
|
+
|
|
79
|
+
Wrap them in your own layout, e.g.:
|
|
80
|
+
|
|
81
|
+
```jsx
|
|
82
|
+
const FormLayout = ({loggedIn, mode, setMode, appBar, children}) => (
|
|
83
|
+
<>
|
|
84
|
+
{loggedIn && <SearchAppBar mode={mode} setMode={setMode} {...appBar} />}
|
|
85
|
+
<Container maxWidth="sm">
|
|
86
|
+
<Grid container>
|
|
87
|
+
<Grid item xs={12}>
|
|
88
|
+
<Card sx={{mt: 2}}>
|
|
89
|
+
<CardContent>{children}</CardContent>
|
|
90
|
+
</Card>
|
|
91
|
+
</Grid>
|
|
92
|
+
</Grid>
|
|
93
|
+
</Container>
|
|
94
|
+
</>
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
<FormLayout loggedIn={!!user.is} mode={mode} setMode={setMode} appBar={appBar}>
|
|
98
|
+
<Login user={user} host={host} />
|
|
99
|
+
</FormLayout>
|
|
100
|
+
```
|
|
61
101
|
|
|
62
102
|
#### Settings
|
|
63
103
|
|
|
64
104
|
A base settings page with name greeting, password change, and logout. Pass app-specific content as `children`, which renders between the greeting and password cards.
|
|
65
105
|
|
|
66
106
|
```jsx
|
|
67
|
-
<Settings
|
|
107
|
+
<Settings
|
|
108
|
+
user={user}
|
|
109
|
+
mode={mode}
|
|
110
|
+
setMode={setMode}
|
|
111
|
+
appBar={appBar}
|
|
112
|
+
buildDate={buildDate}
|
|
113
|
+
>
|
|
68
114
|
<LoginCodes user={user} host={host} code={code} />
|
|
69
115
|
{/* other app-specific settings */}
|
|
70
116
|
</Settings>
|
|
@@ -77,3 +123,13 @@ Displays available login codes for sharing with new users. Returns null when no
|
|
|
77
123
|
#### EditCache
|
|
78
124
|
|
|
79
125
|
Displays audio and video cache contents with options to remove individual items or clear a cache entirely.
|
|
126
|
+
|
|
127
|
+
#### useAccountSync
|
|
128
|
+
|
|
129
|
+
A hook that listens to the host accounts list and keeps the user's contacts in sync. When a contact's public key changes it re-shares any encrypted data under the new key, and adds new contacts automatically when they were referred by the current user.
|
|
130
|
+
|
|
131
|
+
```jsx
|
|
132
|
+
const accountsReady = useAccountSync(holster, user, host, code)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Returns a boolean that becomes `true` once the accounts list has been received for the first time.
|
package/package.json
CHANGED
package/src/components/Login.jsx
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import {useRef, useState} from "react"
|
|
2
2
|
import Box from "@mui/material/Box"
|
|
3
3
|
import Button from "@mui/material/Button"
|
|
4
|
-
import Card from "@mui/material/Card"
|
|
5
|
-
import CardContent from "@mui/material/CardContent"
|
|
6
4
|
import Checkbox from "@mui/material/Checkbox"
|
|
7
|
-
import Container from "@mui/material/Container"
|
|
8
5
|
import FormControl from "@mui/material/FormControl"
|
|
9
6
|
import FormControlLabel from "@mui/material/FormControlLabel"
|
|
10
|
-
import Grid from "@mui/material/Grid"
|
|
11
7
|
import IconButton from "@mui/material/IconButton"
|
|
12
8
|
import InputAdornment from "@mui/material/InputAdornment"
|
|
13
9
|
import InputLabel from "@mui/material/InputLabel"
|
|
@@ -16,15 +12,14 @@ import TextField from "@mui/material/TextField"
|
|
|
16
12
|
import Typography from "@mui/material/Typography"
|
|
17
13
|
import Visibility from "@mui/icons-material/Visibility"
|
|
18
14
|
import VisibilityOff from "@mui/icons-material/VisibilityOff"
|
|
19
|
-
import SearchAppBar from "./SearchAppBar.jsx"
|
|
20
15
|
|
|
21
|
-
const Login = ({user, host
|
|
16
|
+
const Login = ({user, host}) => {
|
|
22
17
|
const [username, setUsername] = useState("")
|
|
23
18
|
const [password, setPassword] = useState("")
|
|
24
19
|
const [showPassword, setShowPassword] = useState(false)
|
|
25
20
|
const [stayLoggedIn, setStayLoggedIn] = useState(false)
|
|
26
21
|
const [message, setMessage] = useState(user.is ? "Already logged in" : "")
|
|
27
|
-
const [disabledButton, setDisabledButton] = useState(user.is)
|
|
22
|
+
const [disabledButton, setDisabledButton] = useState(!!user.is)
|
|
28
23
|
const found = useRef(false)
|
|
29
24
|
|
|
30
25
|
const checkAccount = async () => {
|
|
@@ -111,79 +106,60 @@ const Login = ({user, host, mode, setMode, appBar}) => {
|
|
|
111
106
|
|
|
112
107
|
return (
|
|
113
108
|
<>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
/>
|
|
169
|
-
)}
|
|
170
|
-
{message && (
|
|
171
|
-
<Typography variant="body2">{message}</Typography>
|
|
172
|
-
)}
|
|
173
|
-
<Button
|
|
174
|
-
sx={{ml: "auto"}}
|
|
175
|
-
variant="contained"
|
|
176
|
-
disabled={disabledButton}
|
|
177
|
-
onClick={() => login(username)}
|
|
178
|
-
>
|
|
179
|
-
Submit
|
|
180
|
-
</Button>
|
|
181
|
-
</Box>
|
|
182
|
-
</CardContent>
|
|
183
|
-
</Card>
|
|
184
|
-
</Grid>
|
|
185
|
-
</Grid>
|
|
186
|
-
</Container>
|
|
109
|
+
<Typography variant="h5">Login</Typography>
|
|
110
|
+
<TextField
|
|
111
|
+
id="login-username"
|
|
112
|
+
label="Username"
|
|
113
|
+
variant="outlined"
|
|
114
|
+
fullWidth={true}
|
|
115
|
+
margin="normal"
|
|
116
|
+
value={username}
|
|
117
|
+
onChange={event => setUsername(event.target.value)}
|
|
118
|
+
slotProps={{inputLabel: {shrink: true}}}
|
|
119
|
+
/>
|
|
120
|
+
<FormControl variant="outlined" fullWidth={true} margin="normal">
|
|
121
|
+
<InputLabel htmlFor="login-password">Password</InputLabel>
|
|
122
|
+
<OutlinedInput
|
|
123
|
+
id="login-password"
|
|
124
|
+
type={showPassword ? "text" : "password"}
|
|
125
|
+
value={password}
|
|
126
|
+
onChange={event => setPassword(event.target.value)}
|
|
127
|
+
endAdornment={
|
|
128
|
+
<InputAdornment position="end">
|
|
129
|
+
<IconButton
|
|
130
|
+
aria-label="toggle password visibility"
|
|
131
|
+
onClick={() => setShowPassword(show => !show)}
|
|
132
|
+
edge="end"
|
|
133
|
+
>
|
|
134
|
+
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
135
|
+
</IconButton>
|
|
136
|
+
</InputAdornment>
|
|
137
|
+
}
|
|
138
|
+
label="Password"
|
|
139
|
+
/>
|
|
140
|
+
</FormControl>
|
|
141
|
+
<Box sx={{display: "flex", alignItems: "center", mt: 1}}>
|
|
142
|
+
{!user.is && !message && (
|
|
143
|
+
<FormControlLabel
|
|
144
|
+
control={
|
|
145
|
+
<Checkbox
|
|
146
|
+
checked={stayLoggedIn}
|
|
147
|
+
onChange={e => setStayLoggedIn(e.target.checked)}
|
|
148
|
+
/>
|
|
149
|
+
}
|
|
150
|
+
label="Stay logged in"
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
153
|
+
{message && <Typography variant="body2">{message}</Typography>}
|
|
154
|
+
<Button
|
|
155
|
+
sx={{ml: "auto"}}
|
|
156
|
+
variant="contained"
|
|
157
|
+
disabled={disabledButton}
|
|
158
|
+
onClick={() => login(username)}
|
|
159
|
+
>
|
|
160
|
+
Submit
|
|
161
|
+
</Button>
|
|
162
|
+
</Box>
|
|
187
163
|
</>
|
|
188
164
|
)
|
|
189
165
|
}
|
|
@@ -43,11 +43,7 @@ const LoginCodes = ({user, host, code}) => {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
secret = await user.SEA.secret({epub: epub}, user.is)
|
|
46
|
-
user
|
|
47
|
-
.get([host, "shared"])
|
|
48
|
-
.next("login_codes")
|
|
49
|
-
.next(code)
|
|
50
|
-
.on(update, true)
|
|
46
|
+
user.get([host, "shared"]).next("login_codes").next(code).on(update, true)
|
|
51
47
|
})
|
|
52
48
|
|
|
53
49
|
return () => {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import {useState} from "react"
|
|
2
2
|
import Button from "@mui/material/Button"
|
|
3
|
-
import Card from "@mui/material/Card"
|
|
4
|
-
import CardContent from "@mui/material/CardContent"
|
|
5
|
-
import Container from "@mui/material/Container"
|
|
6
3
|
import FormControl from "@mui/material/FormControl"
|
|
7
|
-
import Grid from "@mui/material/Grid"
|
|
8
4
|
import IconButton from "@mui/material/IconButton"
|
|
9
5
|
import InputAdornment from "@mui/material/InputAdornment"
|
|
10
6
|
import InputLabel from "@mui/material/InputLabel"
|
|
@@ -13,16 +9,15 @@ import TextField from "@mui/material/TextField"
|
|
|
13
9
|
import Typography from "@mui/material/Typography"
|
|
14
10
|
import Visibility from "@mui/icons-material/Visibility"
|
|
15
11
|
import VisibilityOff from "@mui/icons-material/VisibilityOff"
|
|
16
|
-
import SearchAppBar from "./SearchAppBar.jsx"
|
|
17
12
|
|
|
18
|
-
const Register = ({user
|
|
13
|
+
const Register = ({user}) => {
|
|
19
14
|
const [username, setUsername] = useState("")
|
|
20
15
|
const [password, setPassword] = useState("")
|
|
21
16
|
const [showPassword, setShowPassword] = useState(false)
|
|
22
17
|
const [email, setEmail] = useState("")
|
|
23
18
|
const [code, setCode] = useState("")
|
|
24
19
|
const [message, setMessage] = useState(user.is ? "Already logged in" : "")
|
|
25
|
-
const [disabledButton, setDisabledButton] = useState(user.is)
|
|
20
|
+
const [disabledButton, setDisabledButton] = useState(!!user.is)
|
|
26
21
|
|
|
27
22
|
const register = () => {
|
|
28
23
|
if (!username) {
|
|
@@ -97,86 +92,69 @@ const Register = ({user, mode, setMode, appBar}) => {
|
|
|
97
92
|
|
|
98
93
|
return (
|
|
99
94
|
<>
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
<Typography variant="h5">Register</Typography>
|
|
96
|
+
<TextField
|
|
97
|
+
id="register-username"
|
|
98
|
+
label="Username"
|
|
99
|
+
variant="outlined"
|
|
100
|
+
fullWidth={true}
|
|
101
|
+
margin="normal"
|
|
102
|
+
value={username}
|
|
103
|
+
onChange={event => setUsername(event.target.value)}
|
|
104
|
+
slotProps={{inputLabel: {shrink: true}}}
|
|
105
|
+
/>
|
|
106
|
+
<FormControl variant="outlined" fullWidth={true} margin="normal">
|
|
107
|
+
<InputLabel htmlFor="register-password">Password</InputLabel>
|
|
108
|
+
<OutlinedInput
|
|
109
|
+
id="register-password"
|
|
110
|
+
type={showPassword ? "text" : "password"}
|
|
111
|
+
value={password}
|
|
112
|
+
onChange={event => setPassword(event.target.value)}
|
|
113
|
+
endAdornment={
|
|
114
|
+
<InputAdornment position="end">
|
|
115
|
+
<IconButton
|
|
116
|
+
aria-label="toggle password visibility"
|
|
117
|
+
onClick={() => setShowPassword(show => !show)}
|
|
118
|
+
edge="end"
|
|
119
|
+
>
|
|
120
|
+
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
121
|
+
</IconButton>
|
|
122
|
+
</InputAdornment>
|
|
123
|
+
}
|
|
124
|
+
label="Password"
|
|
125
|
+
/>
|
|
126
|
+
</FormControl>
|
|
127
|
+
<TextField
|
|
128
|
+
id="register-email"
|
|
129
|
+
label="Email"
|
|
130
|
+
variant="outlined"
|
|
131
|
+
fullWidth={true}
|
|
132
|
+
margin="normal"
|
|
133
|
+
value={email}
|
|
134
|
+
onChange={event => setEmail(event.target.value)}
|
|
135
|
+
/>
|
|
136
|
+
<TextField
|
|
137
|
+
id="register-code"
|
|
138
|
+
label="Login code"
|
|
139
|
+
variant="outlined"
|
|
140
|
+
fullWidth={true}
|
|
141
|
+
margin="normal"
|
|
142
|
+
value={code}
|
|
143
|
+
onChange={event => setCode(event.target.value)}
|
|
144
|
+
/>
|
|
145
|
+
<Button
|
|
146
|
+
sx={{mt: 1}}
|
|
147
|
+
variant="contained"
|
|
148
|
+
disabled={disabledButton}
|
|
149
|
+
onClick={register}
|
|
150
|
+
>
|
|
151
|
+
Submit
|
|
152
|
+
</Button>
|
|
153
|
+
{message && (
|
|
154
|
+
<Typography sx={{m: 1}} variant="string">
|
|
155
|
+
{message}
|
|
156
|
+
</Typography>
|
|
102
157
|
)}
|
|
103
|
-
<Container maxWidth="sm">
|
|
104
|
-
<Grid container>
|
|
105
|
-
<Grid item xs={12}>
|
|
106
|
-
<Card sx={{mt: 2}}>
|
|
107
|
-
<CardContent>
|
|
108
|
-
<Typography variant="h5">Register</Typography>
|
|
109
|
-
<TextField
|
|
110
|
-
id="register-username"
|
|
111
|
-
label="Username"
|
|
112
|
-
variant="outlined"
|
|
113
|
-
fullWidth={true}
|
|
114
|
-
margin="normal"
|
|
115
|
-
value={username}
|
|
116
|
-
onChange={event => setUsername(event.target.value)}
|
|
117
|
-
InputLabelProps={{shrink: true}}
|
|
118
|
-
/>
|
|
119
|
-
<FormControl
|
|
120
|
-
variant="outlined"
|
|
121
|
-
fullWidth={true}
|
|
122
|
-
margin="normal"
|
|
123
|
-
value={password}
|
|
124
|
-
onChange={event => setPassword(event.target.value)}
|
|
125
|
-
>
|
|
126
|
-
<InputLabel htmlFor="register-password">Password</InputLabel>
|
|
127
|
-
<OutlinedInput
|
|
128
|
-
id="register-password"
|
|
129
|
-
type={showPassword ? "text" : "password"}
|
|
130
|
-
endAdornment={
|
|
131
|
-
<InputAdornment position="end">
|
|
132
|
-
<IconButton
|
|
133
|
-
aria-label="toggle password visibility"
|
|
134
|
-
onClick={() => setShowPassword(show => !show)}
|
|
135
|
-
edge="end"
|
|
136
|
-
>
|
|
137
|
-
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
138
|
-
</IconButton>
|
|
139
|
-
</InputAdornment>
|
|
140
|
-
}
|
|
141
|
-
label="Password"
|
|
142
|
-
/>
|
|
143
|
-
</FormControl>
|
|
144
|
-
<TextField
|
|
145
|
-
id="register-email"
|
|
146
|
-
label="Email"
|
|
147
|
-
variant="outlined"
|
|
148
|
-
fullWidth={true}
|
|
149
|
-
margin="normal"
|
|
150
|
-
value={email}
|
|
151
|
-
onChange={event => setEmail(event.target.value)}
|
|
152
|
-
/>
|
|
153
|
-
<TextField
|
|
154
|
-
id="register-code"
|
|
155
|
-
label="Login code"
|
|
156
|
-
variant="outlined"
|
|
157
|
-
fullWidth={true}
|
|
158
|
-
margin="normal"
|
|
159
|
-
value={code}
|
|
160
|
-
onChange={event => setCode(event.target.value)}
|
|
161
|
-
/>
|
|
162
|
-
<Button
|
|
163
|
-
sx={{mt: 1}}
|
|
164
|
-
variant="contained"
|
|
165
|
-
disabled={disabledButton}
|
|
166
|
-
onClick={register}
|
|
167
|
-
>
|
|
168
|
-
Submit
|
|
169
|
-
</Button>
|
|
170
|
-
{message && (
|
|
171
|
-
<Typography sx={{m: 1}} variant="string">
|
|
172
|
-
{message}
|
|
173
|
-
</Typography>
|
|
174
|
-
)}
|
|
175
|
-
</CardContent>
|
|
176
|
-
</Card>
|
|
177
|
-
</Grid>
|
|
178
|
-
</Grid>
|
|
179
|
-
</Container>
|
|
180
158
|
</>
|
|
181
159
|
)
|
|
182
160
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {useState} from "react"
|
|
2
2
|
import Button from "@mui/material/Button"
|
|
3
|
-
import Card from "@mui/material/Card"
|
|
4
|
-
import CardContent from "@mui/material/CardContent"
|
|
5
|
-
import Container from "@mui/material/Container"
|
|
6
|
-
import Grid from "@mui/material/Grid"
|
|
7
3
|
import TextField from "@mui/material/TextField"
|
|
8
4
|
import Typography from "@mui/material/Typography"
|
|
9
|
-
import SearchAppBar from "./SearchAppBar.jsx"
|
|
10
5
|
|
|
11
|
-
const RequestCode = (
|
|
6
|
+
const RequestCode = () => {
|
|
12
7
|
const [email, setEmail] = useState("")
|
|
13
8
|
const [message, setMessage] = useState("")
|
|
14
9
|
const [disabledButton, setDisabledButton] = useState(false)
|
|
@@ -29,6 +24,10 @@ const RequestCode = ({loggedIn, mode, setMode, appBar}) => {
|
|
|
29
24
|
.then(res => res.text().then(text => ({ok: res.ok, text: text})))
|
|
30
25
|
.then(res => {
|
|
31
26
|
setDisabledButton(false)
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
setMessage(res.text)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
32
31
|
setEmail("")
|
|
33
32
|
setMessage(res.text)
|
|
34
33
|
})
|
|
@@ -36,42 +35,29 @@ const RequestCode = ({loggedIn, mode, setMode, appBar}) => {
|
|
|
36
35
|
|
|
37
36
|
return (
|
|
38
37
|
<>
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
<Typography variant="h5">Request login code</Typography>
|
|
39
|
+
<TextField
|
|
40
|
+
id="request-email"
|
|
41
|
+
label="Email"
|
|
42
|
+
variant="outlined"
|
|
43
|
+
fullWidth={true}
|
|
44
|
+
margin="normal"
|
|
45
|
+
value={email}
|
|
46
|
+
onChange={event => setEmail(event.target.value)}
|
|
47
|
+
/>
|
|
48
|
+
<Button
|
|
49
|
+
sx={{mt: 1}}
|
|
50
|
+
variant="contained"
|
|
51
|
+
disabled={disabledButton}
|
|
52
|
+
onClick={request}
|
|
53
|
+
>
|
|
54
|
+
Submit
|
|
55
|
+
</Button>
|
|
56
|
+
{message && (
|
|
57
|
+
<Typography sx={{m: 1}} variant="string">
|
|
58
|
+
{message}
|
|
59
|
+
</Typography>
|
|
41
60
|
)}
|
|
42
|
-
<Container maxWidth="sm">
|
|
43
|
-
<Grid container>
|
|
44
|
-
<Grid item xs={12}>
|
|
45
|
-
<Card sx={{mt: 2}}>
|
|
46
|
-
<CardContent>
|
|
47
|
-
<Typography variant="h5">Request login code</Typography>
|
|
48
|
-
<TextField
|
|
49
|
-
id="request-email"
|
|
50
|
-
label="Email"
|
|
51
|
-
variant="outlined"
|
|
52
|
-
fullWidth={true}
|
|
53
|
-
margin="normal"
|
|
54
|
-
value={email}
|
|
55
|
-
onChange={event => setEmail(event.target.value)}
|
|
56
|
-
/>
|
|
57
|
-
<Button
|
|
58
|
-
sx={{mt: 1}}
|
|
59
|
-
variant="contained"
|
|
60
|
-
disabled={disabledButton}
|
|
61
|
-
onClick={request}
|
|
62
|
-
>
|
|
63
|
-
Submit
|
|
64
|
-
</Button>
|
|
65
|
-
{message && (
|
|
66
|
-
<Typography sx={{m: 1}} variant="string">
|
|
67
|
-
{message}
|
|
68
|
-
</Typography>
|
|
69
|
-
)}
|
|
70
|
-
</CardContent>
|
|
71
|
-
</Card>
|
|
72
|
-
</Grid>
|
|
73
|
-
</Grid>
|
|
74
|
-
</Container>
|
|
75
61
|
</>
|
|
76
62
|
)
|
|
77
63
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {useState} from "react"
|
|
2
2
|
import Button from "@mui/material/Button"
|
|
3
|
-
import Card from "@mui/material/Card"
|
|
4
|
-
import CardContent from "@mui/material/CardContent"
|
|
5
|
-
import Container from "@mui/material/Container"
|
|
6
|
-
import Grid from "@mui/material/Grid"
|
|
7
3
|
import TextField from "@mui/material/TextField"
|
|
8
4
|
import Typography from "@mui/material/Typography"
|
|
9
|
-
import SearchAppBar from "./SearchAppBar.jsx"
|
|
10
5
|
|
|
11
|
-
const ResetPassword = ({loggedIn
|
|
6
|
+
const ResetPassword = ({loggedIn}) => {
|
|
12
7
|
const [email, setEmail] = useState("")
|
|
13
8
|
const [code, setCode] = useState("")
|
|
14
9
|
const [message, setMessage] = useState(loggedIn ? "Already logged in" : "")
|
|
@@ -27,60 +22,47 @@ const ResetPassword = ({loggedIn, mode, setMode, appBar}) => {
|
|
|
27
22
|
headers: {"Content-Type": "application/json;charset=utf-8"},
|
|
28
23
|
body: JSON.stringify({email: email, code: code}),
|
|
29
24
|
})
|
|
30
|
-
.then(res => res.text())
|
|
25
|
+
.then(res => res.text().then(text => ({ok: res.ok, text: text})))
|
|
31
26
|
.then(res => {
|
|
32
27
|
setDisabledButton(false)
|
|
33
|
-
setMessage(res)
|
|
28
|
+
setMessage(res.text)
|
|
34
29
|
})
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
return (
|
|
38
33
|
<>
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
<Typography variant="h5">Reset Password</Typography>
|
|
35
|
+
<TextField
|
|
36
|
+
id="reset-password-email"
|
|
37
|
+
label="Email"
|
|
38
|
+
variant="outlined"
|
|
39
|
+
fullWidth={true}
|
|
40
|
+
margin="normal"
|
|
41
|
+
value={email}
|
|
42
|
+
onChange={event => setEmail(event.target.value)}
|
|
43
|
+
/>
|
|
44
|
+
<TextField
|
|
45
|
+
id="reset-password-code"
|
|
46
|
+
label="Login code"
|
|
47
|
+
variant="outlined"
|
|
48
|
+
fullWidth={true}
|
|
49
|
+
margin="normal"
|
|
50
|
+
value={code}
|
|
51
|
+
onChange={event => setCode(event.target.value)}
|
|
52
|
+
/>
|
|
53
|
+
<Button
|
|
54
|
+
sx={{mt: 1}}
|
|
55
|
+
variant="contained"
|
|
56
|
+
disabled={disabledButton}
|
|
57
|
+
onClick={reset}
|
|
58
|
+
>
|
|
59
|
+
Submit
|
|
60
|
+
</Button>
|
|
61
|
+
{message && (
|
|
62
|
+
<Typography sx={{m: 1}} variant="string">
|
|
63
|
+
{message}
|
|
64
|
+
</Typography>
|
|
41
65
|
)}
|
|
42
|
-
<Container maxWidth="sm">
|
|
43
|
-
<Grid container>
|
|
44
|
-
<Grid item xs={12}>
|
|
45
|
-
<Card sx={{mt: 2}}>
|
|
46
|
-
<CardContent>
|
|
47
|
-
<Typography variant="h5">Reset Password</Typography>
|
|
48
|
-
<TextField
|
|
49
|
-
id="reset-password-email"
|
|
50
|
-
label="Email"
|
|
51
|
-
variant="outlined"
|
|
52
|
-
fullWidth={true}
|
|
53
|
-
margin="normal"
|
|
54
|
-
value={email}
|
|
55
|
-
onChange={event => setEmail(event.target.value)}
|
|
56
|
-
/>
|
|
57
|
-
<TextField
|
|
58
|
-
id="reset-password-code"
|
|
59
|
-
label="Login code"
|
|
60
|
-
variant="outlined"
|
|
61
|
-
fullWidth={true}
|
|
62
|
-
margin="normal"
|
|
63
|
-
value={code}
|
|
64
|
-
onChange={event => setCode(event.target.value)}
|
|
65
|
-
/>
|
|
66
|
-
<Button
|
|
67
|
-
sx={{mt: 1}}
|
|
68
|
-
variant="contained"
|
|
69
|
-
disabled={disabledButton}
|
|
70
|
-
onClick={reset}
|
|
71
|
-
>
|
|
72
|
-
Submit
|
|
73
|
-
</Button>
|
|
74
|
-
{message && (
|
|
75
|
-
<Typography sx={{m: 1}} variant="string">
|
|
76
|
-
{message}
|
|
77
|
-
</Typography>
|
|
78
|
-
)}
|
|
79
|
-
</CardContent>
|
|
80
|
-
</Card>
|
|
81
|
-
</Grid>
|
|
82
|
-
</Grid>
|
|
83
|
-
</Container>
|
|
84
66
|
</>
|
|
85
67
|
)
|
|
86
68
|
}
|