refactor handleRegistrationResponse

This commit is contained in:
Ben Wheeler 2019-09-03 18:27:11 -04:00
parent 643b4a611b
commit 1d976c7cdf

View file

@ -27,6 +27,7 @@ class JoinFlow extends React.Component {
bindAll(this, [ bindAll(this, [
'handleAdvanceStep', 'handleAdvanceStep',
'handlePrepareToRegister', 'handlePrepareToRegister',
'handleRegistrationResponse',
'handleSubmitRegistration' 'handleSubmitRegistration'
]); ]);
this.state = { this.state = {
@ -45,29 +46,7 @@ class JoinFlow extends React.Component {
this.handleSubmitRegistration(this.state.formData); this.handleSubmitRegistration(this.state.formData);
}); });
} }
handleSubmitRegistration (formData) { handleRegistrationResponse (err, body, res) {
this.setState({waiting: true}, () => {
api({
host: '',
uri: '/accounts/register_new_user/',
method: 'post',
useCsrf: true,
formData: {
'username': formData.username,
'email': formData.email,
'password': formData.password,
'birth_month': formData.birth_month,
'birth_year': formData.birth_year,
'g-recaptcha-response': null,
'gender': formData.gender,
'country': formData.country,
'subscribe': true,
'is_robot': formData.yesno
// no need to include csrfmiddlewaretoken; will be provided in
// X-CSRFToken header, which scratchr2 looks for in
// scratchr2/middleware/csrf.py line 237.
}
}, (err, body, res) => {
this.setState({waiting: false}, () => { this.setState({waiting: false}, () => {
let errStr = ''; let errStr = '';
if (!err && res.statusCode === 200) { if (!err && res.statusCode === 200) {
@ -102,6 +81,31 @@ class JoinFlow extends React.Component {
})} (${res.statusCode})` })} (${res.statusCode})`
}); });
}); });
}
handleSubmitRegistration (formData) {
this.setState({waiting: true}, () => {
api({
host: '',
uri: '/accounts/register_new_user/',
method: 'post',
useCsrf: true,
formData: {
'username': formData.username,
'email': formData.email,
'password': formData.password,
'birth_month': formData.birth_month,
'birth_year': formData.birth_year,
'g-recaptcha-response': null,
'gender': formData.gender,
'country': formData.country,
'subscribe': true,
'is_robot': formData.yesno
// no need to include csrfmiddlewaretoken; will be provided in
// X-CSRFToken header, which scratchr2 looks for in
// scratchr2/middleware/csrf.py line 237.
}
}, (err, body, res) => {
this.handleRegistrationResponse(err, body, res);
}); });
}); });
} }