2018-09-09 17:22:44 -04:00
|
|
|
import React, { Component } from 'react';
|
2019-11-07 02:39:26 -05:00
|
|
|
import { Link, Redirect } from 'react-router-dom';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2020-01-02 05:59:13 -05:00
|
|
|
import { apiGet, apiPost } from '../apiHelpers';
|
2019-08-14 04:02:57 -04:00
|
|
|
import ErrorBox from '../components/error-box';
|
|
|
|
import InfoBox from '../components/info-box';
|
|
|
|
import SupporterLogos from '../components/supporter-logos';
|
2019-11-05 15:13:10 -05:00
|
|
|
import { User } from '../models/user';
|
2018-09-13 11:58:05 -04:00
|
|
|
|
2019-11-05 15:13:10 -05:00
|
|
|
interface SignUpProps {
|
|
|
|
login: (user: User) => void;
|
|
|
|
user: User;
|
|
|
|
}
|
2019-08-13 16:17:39 -04:00
|
|
|
|
2019-11-05 15:13:10 -05:00
|
|
|
interface SignUpState {
|
|
|
|
username: string;
|
|
|
|
email: string;
|
|
|
|
confirm_email: string;
|
|
|
|
show_password: boolean;
|
|
|
|
password: string;
|
|
|
|
confirm_conditions: boolean;
|
|
|
|
error: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SignUp extends Component<SignUpProps, SignUpState> {
|
2018-09-09 17:22:44 -04:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
confirm_email: '',
|
|
|
|
password: '',
|
2019-11-05 15:13:10 -05:00
|
|
|
show_password: false,
|
2018-09-13 11:58:05 -04:00
|
|
|
confirm_conditions: false,
|
|
|
|
error: undefined
|
2018-09-09 17:22:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(event) {
|
|
|
|
const target = event.target;
|
|
|
|
const value = target.type === 'checkbox' ? target.checked : target.value;
|
2019-11-05 15:13:10 -05:00
|
|
|
const name: keyof SignUpState = target.name;
|
2018-09-09 17:22:44 -04:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
[name]: value
|
2019-11-05 15:13:10 -05:00
|
|
|
} as Pick<SignUpState, keyof SignUpState>);
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
|
|
|
|
2020-01-02 05:59:13 -05:00
|
|
|
async handleSubmit(event) {
|
2018-09-09 17:22:44 -04:00
|
|
|
event.preventDefault();
|
2019-11-07 03:13:30 -05:00
|
|
|
this.setState({error: undefined});
|
2018-09-13 12:02:27 -04:00
|
|
|
|
2020-01-02 05:59:13 -05:00
|
|
|
try {
|
|
|
|
const res = await apiPost('/api/users', this.state);
|
|
|
|
if(res.error) {
|
|
|
|
this.setState({ error: res.error });
|
2018-09-09 17:22:44 -04:00
|
|
|
} else {
|
2020-01-02 05:59:13 -05:00
|
|
|
const user = await apiGet('/api/users/me');
|
|
|
|
this.props.login(user);
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
2020-01-02 05:59:13 -05:00
|
|
|
} catch(err) {
|
|
|
|
this.setState({error: err});
|
|
|
|
}
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.props.user) {
|
2019-11-07 03:13:30 -05:00
|
|
|
return <Redirect to="/my-account.html" />;
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<article>
|
|
|
|
<section className="main-col">
|
|
|
|
<h1 className="h2">Sign up</h1>
|
2018-11-21 16:08:55 -05:00
|
|
|
<InfoBox msg="Welcome to Colouring London. You're one of the first people to sign up! ">
|
|
|
|
<br/>Please <a href="https://discuss.colouring.london/">discuss
|
|
|
|
suggestions for improvements</a> and <a
|
2019-05-27 11:39:16 -04:00
|
|
|
href="https://github.com/tomalrussell/colouring-london/issues">
|
2018-11-21 16:08:55 -05:00
|
|
|
report issues or problems</a>.
|
|
|
|
</InfoBox>
|
2018-09-09 17:22:44 -04:00
|
|
|
<p>
|
|
|
|
Create an account to start colouring in.
|
|
|
|
</p>
|
2018-09-13 11:58:05 -04:00
|
|
|
<ErrorBox msg={this.state.error} />
|
2018-09-09 17:22:44 -04:00
|
|
|
<form onSubmit={this.handleSubmit}>
|
|
|
|
<label htmlFor="username">Username*</label>
|
|
|
|
<input name="username" id="username"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-control" type="text"
|
|
|
|
value={this.state.username} onChange={this.handleChange}
|
|
|
|
placeholder="not-your-real-name" required
|
2019-09-18 10:20:56 -04:00
|
|
|
minLength={4}
|
|
|
|
maxLength={30}
|
|
|
|
pattern="\w+"
|
|
|
|
title="Usernames can contain only letters, numbers and the underscore"
|
2019-05-27 11:39:16 -04:00
|
|
|
/>
|
2018-09-09 17:22:44 -04:00
|
|
|
|
|
|
|
<label htmlFor="email">Email (optional)</label>
|
|
|
|
<input name="email" id="email"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-control" type="email"
|
|
|
|
value={this.state.email} onChange={this.handleChange}
|
|
|
|
placeholder="someone@example.com"
|
|
|
|
/>
|
2019-10-02 14:17:25 -04:00
|
|
|
<InfoBox msg="Please note that if you forget your password, you will only be able to recover your account if you provide an email address." />
|
2018-09-09 17:22:44 -04:00
|
|
|
<label htmlFor="confirm_email">Confirm email (optional)</label>
|
|
|
|
<input name="confirm_email" id="confirm_email"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-control" type="email"
|
|
|
|
value={this.state.confirm_email} onChange={this.handleChange}
|
|
|
|
/>
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2018-11-21 16:08:55 -05:00
|
|
|
<label htmlFor="password">Password (at least 8 characters)</label>
|
2018-09-09 17:22:44 -04:00
|
|
|
<input name="password" id="password"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-control"
|
|
|
|
type={(this.state.show_password)? 'text': 'password'}
|
|
|
|
value={this.state.password} onChange={this.handleChange}
|
|
|
|
required
|
2019-09-18 10:20:56 -04:00
|
|
|
minLength={8}
|
|
|
|
maxLength={128}
|
2019-05-27 11:39:16 -04:00
|
|
|
/>
|
2018-09-09 17:22:44 -04:00
|
|
|
|
|
|
|
<div className="form-check">
|
|
|
|
<input id="show_password" name="show_password"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-check-input" type="checkbox"
|
|
|
|
checked={this.state.show_password}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
/>
|
2018-09-13 11:58:05 -04:00
|
|
|
<label className="form-check-label" htmlFor="show_password">
|
|
|
|
Show password?
|
|
|
|
</label>
|
2018-09-09 17:22:44 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="form-check">
|
|
|
|
<input id="confirm_conditions" name="confirm_conditions"
|
2019-05-27 11:39:16 -04:00
|
|
|
className="form-check-input" type="checkbox"
|
|
|
|
checked={this.state.confirm_conditions}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
required />
|
2018-09-13 11:58:05 -04:00
|
|
|
<label className="form-check-label" htmlFor="confirm_conditions">
|
2019-08-13 16:17:39 -04:00
|
|
|
I confirm that I have read and agree to the <Link
|
2019-10-02 14:26:18 -04:00
|
|
|
to="/privacy-policy.html">privacy policy</Link>, <Link
|
|
|
|
to="/contributor-agreement.html">contributor agreement</Link> and <Link
|
|
|
|
to="/data-accuracy.html">data accuracy agreement</Link>.
|
2018-09-09 17:22:44 -04:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
2019-10-02 14:17:25 -04:00
|
|
|
<div className="buttons-container with-space">
|
2018-09-13 11:09:41 -04:00
|
|
|
<input type="submit" value="Sign Up" className="btn btn-primary" />
|
|
|
|
</div>
|
2020-12-04 20:07:59 -05:00
|
|
|
<InfoBox msg="">
|
|
|
|
Please also read our <a href="https://www.pages.colouring.london/data-ethics">data ethics policy</a> before using or sharing our data
|
|
|
|
</InfoBox>
|
2018-09-13 11:09:41 -04:00
|
|
|
|
|
|
|
Do you already have an account?
|
|
|
|
|
2019-10-02 14:17:25 -04:00
|
|
|
<div className="buttons-container with-space">
|
2018-09-13 11:09:41 -04:00
|
|
|
<Link to="login.html" className="btn btn-outline-dark">Log in</Link>
|
|
|
|
</div>
|
|
|
|
|
2018-09-09 17:22:44 -04:00
|
|
|
</form>
|
|
|
|
</section>
|
2018-09-17 16:27:52 -04:00
|
|
|
<hr />
|
|
|
|
<section className="main-col">
|
|
|
|
<SupporterLogos />
|
|
|
|
</section>
|
2018-09-09 17:22:44 -04:00
|
|
|
</article>
|
2019-11-07 03:13:30 -05:00
|
|
|
);
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SignUp;
|