forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUp.js
More file actions
84 lines (78 loc) · 2.37 KB
/
Copy pathSignUp.js
File metadata and controls
84 lines (78 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { useEffect, useState } from 'react';
import { Redirect } from 'react-router-dom';
import { connect } from 'unistore/react';
import Button from './common/Button';
import Input from './common/Input';
import message from './common/message';
import Spacer from './common/Spacer';
import fetchJson from './utilities/fetch-json.js';
function SignUp({ adminRegistrationOpen }) {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [passwordConfirmation, setPasswordConfirmation] = useState('');
const [redirect, setRedirect] = useState(false);
useEffect(() => {
document.title = 'SQLPad - Sign Up';
}, []);
const signUp = async e => {
e.preventDefault();
const json = await fetchJson('POST', '/api/signup', {
email,
password,
passwordConfirmation
});
if (json.error) {
return message.error(json.error);
}
setRedirect(true);
};
if (redirect) {
return <Redirect to="/" />;
}
return (
<div style={{ width: '300px', textAlign: 'center', margin: '100px auto' }}>
<form onSubmit={signUp}>
<h1>SQLPad</h1>
{adminRegistrationOpen && (
<div>
<h2>Admin registration open</h2>
<p>
Welcome to SQLPad! Since there are no admins currently registered,
signup is open to anyone. By signing up, you will be granted admin
rights, and signup will be restricted to whitelisted email
addresses/domains
</p>
</div>
)}
<Input
name="email"
type="email"
placeholder="Email address"
onChange={e => setEmail(e.target.value)}
required
/>
<Spacer />
<Input
name="password"
type="password"
placeholder="Password"
onChange={e => setPassword(e.target.value)}
required
/>
<Spacer />
<Input
name="passwordConfirmation"
type="password"
placeholder="Confirm Password"
onChange={e => setPasswordConfirmation(e.target.value)}
required
/>
<Spacer size={2} />
<Button style={{ width: '100%' }} htmlType="submit" type="primary">
Sign up
</Button>
</form>
</div>
);
}
export default connect(['adminRegistrationOpen'])(SignUp);