2016-05-01 23:20:55 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
|
|
import accounts from 'services/api/accounts';
|
2016-05-02 14:50:50 +05:30
|
|
|
import FormModel from 'models/Form';
|
2016-05-01 23:20:55 +05:30
|
|
|
import ChangePassword from 'components/profile/changePassword/ChangePassword';
|
|
|
|
import PasswordRequestForm from 'components/profile/passwordRequestForm/PasswordRequestForm';
|
|
|
|
|
|
|
|
class ChangePasswordPage extends Component {
|
|
|
|
static displayName = 'ChangePasswordPage';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
changePassword: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
form = new FormModel();
|
|
|
|
|
2016-05-01 23:20:55 +05:30
|
|
|
render() {
|
|
|
|
return (
|
2016-05-02 14:50:50 +05:30
|
|
|
<ChangePassword onSubmit={this.onSubmit} form={this.form} />
|
2016-05-01 23:20:55 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:50:50 +05:30
|
|
|
onSubmit = () => {
|
|
|
|
this.props.changePassword(this.form);
|
2016-05-01 23:20:55 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { routeActions } from 'react-router-redux';
|
|
|
|
import { register as registerPopup, create as createPopup } from 'components/ui/popup/actions';
|
2016-05-01 23:40:45 +05:30
|
|
|
import { updateUser } from 'components/user/actions';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
function goToProfile() {
|
|
|
|
return routeActions.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(null, {
|
2016-05-02 14:50:50 +05:30
|
|
|
changePassword: (form) => {
|
2016-05-01 23:20:55 +05:30
|
|
|
return (dispatch) => {
|
2016-05-02 14:50:50 +05:30
|
|
|
// TODO: судя по всему registerPopup было явно лишним. Надо еще раз
|
|
|
|
// обдумать API и переписать
|
2016-05-01 23:20:55 +05:30
|
|
|
dispatch(registerPopup('requestPassword', PasswordRequestForm));
|
|
|
|
dispatch(createPopup('requestPassword', (props) => {
|
|
|
|
return {
|
2016-05-02 14:50:50 +05:30
|
|
|
form,
|
|
|
|
onSubmit: () => {
|
2016-05-01 23:40:45 +05:30
|
|
|
// TODO: hide this logic in action
|
2016-05-02 14:50:50 +05:30
|
|
|
accounts.changePassword(form.serialize())
|
|
|
|
.catch((resp) => {
|
|
|
|
if (resp.errors) {
|
|
|
|
form.setErrors(resp.errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(resp);
|
2016-05-01 23:20:55 +05:30
|
|
|
})
|
2016-05-01 23:40:45 +05:30
|
|
|
.then(() => {
|
|
|
|
dispatch(updateUser({
|
|
|
|
passwordChangedAt: Date.now() / 1000,
|
|
|
|
shouldChangePassword: false
|
|
|
|
}));
|
|
|
|
})
|
2016-05-01 23:20:55 +05:30
|
|
|
.then(props.onClose)
|
|
|
|
.then(() => dispatch(goToProfile()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})(ChangePasswordPage);
|