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

Commit

Permalink
- reset password request #1878
Browse files Browse the repository at this point in the history
  • Loading branch information
siemiatj committed Aug 7, 2018
1 parent 6567a19 commit 3057c7a
Showing 1 changed file with 61 additions and 80 deletions.
141 changes: 61 additions & 80 deletions src/components/app/PasswordRecovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PasswordRecovery extends Component {
const { token } = this.props;

resetPasswordGetAvatar(token).then(({ data }) => {
console.log('DATA: ', data)
this.setState({
avatarSrc: data,
});
Expand All @@ -52,12 +53,12 @@ class PasswordRecovery extends Component {
const { token } = this.props;
const { form } = this.state;

getResetPasswordInfo(token).then(resp => {
getResetPasswordInfo(token).then(({ data }) => {
this.setState({
form: {
...form,
email: resp.data.email,
fullname: resp.data.fullname
email: data.email,
fullname: data.fullname,
},
});
});
Expand All @@ -72,14 +73,29 @@ class PasswordRecovery extends Component {

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;
if (token) {
if (password !== re_password) {
this.setState({
err: counterpart.translate(
'forgotPassword.error.retypedNewPasswordNotMatch'
),
});
}
}
}
);
};

handleSubmit = e => {
Expand All @@ -95,14 +111,37 @@ class PasswordRecovery extends Component {

if (resetPassword) {
// add email (so we need to save it when loading page)
this.setState(
{
pending: true,
err: '',
},
() => {
resetPasswordComplete({
email: form.email,
password: form.password,
token,
})
.then(() => {
this.setState({
resetEmailSent: true,
pending: false,
});
})
.catch(error => {
this.setState({ err: error.data.message, pending: false });
});
}
);
} else {
this.setState(
{
pending: true,
err: '',
},
() => {
resetPasswordRequest(form)
.then(response => {
.then(() => {
this.setState({
resetEmailSent: true,
pending: false,
Expand Down Expand Up @@ -131,74 +170,6 @@ class PasswordRecovery extends Component {
// });
// };

// handleLogin = () => {
// const { dispatch, auth } = this.props;
// const { roleSelect, role } = this.state;

// this.setState(
// {
// pending: true,
// },
// () => {
// if (roleSelect) {
// return loginCompletionRequest(role)
// .then(() => {
// dispatch(loginSuccess(auth));
// this.handleSuccess();
// })
// .catch(err => {
// this.setState({
// err: err.response
// ? err.response.data.message
// : counterpart.translate('login.error.fallback'),
// pending: false,
// });
// });
// }

// loginRequest(this.login.value, this.passwd.value)
// .then(response => {
// if (response.data.loginComplete) {
// return this.handleSuccess();
// }
// const roles = List(response.data.roles);

// this.setState({
// roleSelect: true,
// roles,
// role: roles.get(0),
// });
// })
// .then(() => {
// this.setState({
// pending: false,
// });
// })
// .catch(err => {
// return this.checkIfAlreadyLogged(err);
// })
// .catch(err => {
// this.setState({
// err: err.response
// ? err.response.data.message
// : counterpart.translate('login.error.fallback'),
// pending: false,
// });
// });
// }
// );
// };

// onFocus = () => {
// this.setState({
// dropdownFocused: true,
// });
// };

// onBlur = () => {
// this.setState({ dropdownFocused: false });
// };

renderForgottenPasswordForm = () => {
const { pending, err } = this.state;

Expand Down Expand Up @@ -253,7 +224,11 @@ class PasswordRecovery extends Component {
</div>
<div>
<div className="form-control-label">
<small>{counterpart.translate('login.password.caption')}</small>
<small>
{counterpart.translate(
'forgotPassword.retypeNewPassword.caption'
)}
</small>
</div>
<input
type="password"
Expand Down Expand Up @@ -300,7 +275,7 @@ class PasswordRecovery extends Component {
{avatarSrc && (
<div>
<div className="text-center">
<img src={avatarSrc} className="avatar mt-2 mb-2" />
<img src={`data:image/*;base64,${avatarSrc}`} className="avatar mt-2 mb-2" />
</div>
<div className="text-center">
<span className="user-data">{form.fullname}</span>
Expand All @@ -326,4 +301,10 @@ class PasswordRecovery extends Component {
}
}

PasswordRecovery.propTypes = {
dispatch: PropTypes.func.isRequired,
path: PropTypes.string.isRequired,
token: PropTypes.string,
};

export default connect()(PasswordRecovery);

0 comments on commit 3057c7a

Please sign in to comment.