From eabcbc36c64cda59810a89967cb958fe55377a03 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Fri, 4 May 2018 13:34:20 -0300 Subject: [PATCH] forgot password --- .../client/components/ChangePassword.js | 23 ++++++++++++++- .../client/containers/ChangePassword.js | 29 +++++++++++++++---- .../client/translations.yml | 2 ++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js index e5535b8ba..04d420d22 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js +++ b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js @@ -125,6 +125,23 @@ class ChangePassword extends React.Component { this.disableEditing(); }; + onForgotPassword = async () => { + const { root: { me: { email } } } = this.props; + + try { + await this.props.forgotPassword(email); + this.props.notify( + 'success', + t('talk-plugin-local-auth.change_password.forgot_password_sent') + ); + } catch (err) { + this.props.notify('error', getErrorMessages(err)); + } + + this.clearForm(); + this.disableEditing(); + }; + disableEditing = () => { this.setState({ editing: false, @@ -166,7 +183,10 @@ class ChangePassword extends React.Component { showErrors > - + {t('talk-plugin-local-auth.change_password.forgot_password')} @@ -223,6 +243,7 @@ class ChangePassword extends React.Component { ChangePassword.propTypes = { changePassword: PropTypes.func.isRequired, + forgotPassword: PropTypes.func.isRequired, notify: PropTypes.func.isRequired, }; diff --git a/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js b/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js index 1322a2940..dfcf4a143 100644 --- a/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js +++ b/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js @@ -1,12 +1,29 @@ -import { compose } from 'react-apollo'; +import { compose, gql } from 'react-apollo'; import { bindActionCreators } from 'redux'; -import { connect } from 'plugin-api/beta/client/hocs'; +import { connect, withFragments } from 'plugin-api/beta/client/hocs'; import ChangePassword from '../components/ChangePassword'; import { notify } from 'coral-framework/actions/notification'; -import { withChangePassword } from 'plugin-api/beta/client/hocs'; +import { + withChangePassword, + withForgotPassword, +} from 'plugin-api/beta/client/hocs'; const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch); -export default compose(connect(null, mapDispatchToProps), withChangePassword)( - ChangePassword -); +const withData = withFragments({ + root: gql` + fragment TalkPluginLocalAuth_ChangePassword_root on RootQuery { + me { + id + email + } + } + `, +}); + +export default compose( + connect(null, mapDispatchToProps), + withChangePassword, + withForgotPassword, + withData +)(ChangePassword); diff --git a/plugins/talk-plugin-local-auth/client/translations.yml b/plugins/talk-plugin-local-auth/client/translations.yml index d3b323f54..0c3216009 100644 --- a/plugins/talk-plugin-local-auth/client/translations.yml +++ b/plugins/talk-plugin-local-auth/client/translations.yml @@ -9,6 +9,7 @@ en: cancel: "Cancel" edit: "Edit" changed_password_msg: "Changed Password - Your password has been successfully changed" + forgot_password_sent: "Forgot Password - We sent you an email to recover your password" change_username: change_username_note: "Usernames can be changed every 14 days" save: "Save" @@ -46,6 +47,7 @@ es: cancel: "Cancelar" edit: "Editar" changed_password_msg: "Contraseña Actualizada - Tu contraseña ha sido exitosamente actualizada" + forgot_password_sent: "Contraseña Olvidada - Te enviamos un email para recuperar tu contraseña" change_username: change_username_note: "El usuario puede ser cambiado cada 14 días" save: "Guardar"