Password recovery completed

This commit is contained in:
2019-05-09 09:23:10 +10:00
parent 3a34d78712
commit b023c74495
10 changed files with 477 additions and 15 deletions
@@ -0,0 +1,99 @@
import React from 'react';
import { validateEmail } from '../../../common/utilities.js';
class PasswordRecover extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
warning: ''
};
}
render() {
let warningStyle = {
display: this.state.warning.length > 0 ? 'flex' : 'none'
};
return (
<div className='panel'>
<h1>Recover Password</h1>
<div className='warning' style={warningStyle}>
<p>{this.state.warning}</p>
</div>
<form action='/passwordrecover' method='post' onSubmit={(e) => this.submit(e)}>
<div>
<label>Email:</label>
<input type='text' name='email' value={this.state.email} onChange={this.updateEmail.bind(this)} />
</div>
<button type='submit'>Send Email</button>
</form>
</div>
);
}
submit(e) {
e.preventDefault();
if (!this.validateInput()) {
return;
}
//build the XHR
let form = e.target;
let formData = new FormData(form);
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
//DEBUGGING
if (this.props.onEmailSent) {
this.props.onEmailSent(xhr.responseText);
}
}
else if (xhr.status === 400) {
this.setWarning(xhr.responseText);
}
}
};
//send the XHR
xhr.open('POST', form.action, true);
xhr.send(formData);
}
validateInput(e) {
if (!validateEmail(this.state.email)) {
this.setWarning('Invalid Email');
return false;
}
return true;
}
setWarning(s) {
this.setState({
warning: s
});
}
clearInput() {
this.setState({
email: '',
warning: ''
});
}
updateEmail(evt) {
this.setState({
email: evt.target.value
});
}
}
export default PasswordRecover;