From eabcbc36c64cda59810a89967cb958fe55377a03 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Fri, 4 May 2018 13:34:20 -0300 Subject: [PATCH 1/3] 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" From d41984f171e0b00dfdb1e4670b5340597b184136 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 4 May 2018 19:32:29 +0200 Subject: [PATCH 2/3] Remove unused field --- .../talk-plugin-local-auth/client/containers/ChangePassword.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js b/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js index dfcf4a143..11bd5c5fb 100644 --- a/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js +++ b/plugins/talk-plugin-local-auth/client/containers/ChangePassword.js @@ -14,7 +14,6 @@ const withData = withFragments({ root: gql` fragment TalkPluginLocalAuth_ChangePassword_root on RootQuery { me { - id email } } From 2a5075f434d21394a86e6977e3c6ce895ecb4681 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 4 May 2018 11:33:06 -0600 Subject: [PATCH 3/3] Form update --- .../client/components/ChangePassword.js | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js index 04d420d22..8f86fff48 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js +++ b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js @@ -105,7 +105,13 @@ class ChangePassword extends React.Component { this.setState(initialState); }; - onSave = async () => { + onSave = async e => { + e.preventDefault(); + + if (this.isSubmitBlocked()) { + return; + } + const { oldPassword, newPassword } = this.state.formData; try { @@ -169,8 +175,11 @@ class ChangePassword extends React.Component {

{t('talk-plugin-local-auth.change_password.change_password')}

- {editing && ( -
+ {editing ? ( + +
+ + + {t('talk-plugin-local-auth.change_password.cancel')} + +
- )} - {editing ? ( -
- - - {t('talk-plugin-local-auth.change_password.cancel')} - -
) : (