Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
- improve matching passwords check #1878
Browse files Browse the repository at this point in the history
  • Loading branch information
siemiatj committed Aug 14, 2018
1 parent 530b6c0 commit f6c6e5b
Showing 1 changed file with 45 additions and 66 deletions.
111 changes: 45 additions & 66 deletions src/components/app/PasswordRecovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,16 @@ class PasswordRecovery extends Component {
dispatch(push('/login'));
};

handleKeyPress = e => {
if (e.key === 'Enter') {
this.form.submit();
}
};

handleChange = (e, name) => {
e.preventDefault();
const { token } = this.props;

this.setState(
{
err: '',
form: {
...this.state.form,
[`${name}`]: e.target.value,
},
this.setState({
err: '',
form: {
...this.state.form,
[`${name}`]: e.target.value,
},
() => {
const { password, re_password } = this.state.form;

setTimeout(() => {
if (token) {
if (password !== re_password) {
this.setState({
err: counterpart.translate(
'forgotPassword.error.retypedNewPasswordNotMatch'
),
});
} else {
// because timeout
this.setState({
err: '',
});
}
}
}, 500);
}
);
});
};

handleSubmit = e => {
Expand All @@ -121,29 +92,39 @@ class PasswordRecovery extends Component {
}

if (resetPassword) {
// add email (so we need to save it when loading page)
this.setState(
{
pending: true,
err: '',
},
() => {
resetPasswordComplete(token, {
email: form.email,
password: form.password,
token,
})
.then(response => onResetOk(response))
.catch(err => {
this.setState({
err: err.response
? err.response.data.message
: counterpart.translate('login.error.fallback'),
pending: false,
const { password, re_password } = this.state.form;

if (password !== re_password) {
this.setState({
err: counterpart.translate(
'forgotPassword.error.retypedNewPasswordNotMatch'
),
});
} else {
// add email (so we need to save it when loading page)
this.setState(
{
pending: true,
err: '',
},
() => {
resetPasswordComplete(token, {
email: form.email,
password: form.password,
token,
})
.then(response => onResetOk(response))
.catch(err => {
this.setState({
err: err.response
? err.response.data.message
: counterpart.translate('login.error.fallback'),
pending: false,
});
});
});
}
);
}
);
}
} else {
this.setState(
{
Expand Down Expand Up @@ -281,11 +262,12 @@ class PasswordRecovery extends Component {

return (
<div>
{avatarSrc && (
<div className="text-center">
<img src={avatarSrc} className="avatar mt-2 mb-2" />
</div>
)}
{resetPassword &&
avatarSrc && (
<div className="text-center">
<img src={avatarSrc} className="avatar mt-2 mb-2" />
</div>
)}
{form.fullname && (
<div className="text-center">
<span className="user-data">{form.fullname}</span>
Expand Down Expand Up @@ -319,10 +301,7 @@ class PasswordRecovery extends Component {
: this.renderContent();

return (
<div
className="login-form panel panel-spaced-lg panel-shadowed panel-primary"
onKeyPress={this.handleKeyPress}
>
<div className="login-form panel panel-spaced-lg panel-shadowed panel-primary">
<div className="text-center">
<img src={logo} className="header-logo mt-2 mb-2" />
</div>
Expand Down

0 comments on commit f6c6e5b

Please sign in to comment.