diff --git a/src/pages/signin/PasswordForm.js b/src/pages/signin/PasswordForm.js index 3f9a9abb55b7..430de26a1829 100755 --- a/src/pages/signin/PasswordForm.js +++ b/src/pages/signin/PasswordForm.js @@ -47,6 +47,7 @@ class PasswordForm extends React.Component { constructor(props) { super(props); this.validateAndSubmitForm = this.validateAndSubmitForm.bind(this); + this.resetPassword = this.resetPassword.bind(this); this.state = { formError: false, @@ -56,15 +57,15 @@ class PasswordForm extends React.Component { } componentDidMount() { - if (!canFocusInputOnScreenFocus() || !this.input || !this.props.isVisible) { + if (!canFocusInputOnScreenFocus() || !this.inputPassword || !this.props.isVisible) { return; } - this.input.focus(); + this.inputPassword.focus(); } componentDidUpdate(prevProps) { if (!prevProps.isVisible && this.props.isVisible) { - this.input.focus(); + this.inputPassword.focus(); } if (prevProps.isVisible && !this.props.isVisible && this.state.password) { this.clearPassword(); @@ -75,7 +76,15 @@ class PasswordForm extends React.Component { * Clear Password from the state */ clearPassword() { - this.setState({password: ''}, this.input.clear); + this.setState({password: ''}, this.inputPassword.clear); + } + + /** + * Trigger the reset password flow and ensure the 2FA input field is reset to avoid it being permanently hidden + */ + resetPassword() { + this.setState({twoFactorAuthCode: ''}, this.input2FA.clear); + Session.resetPassword(); } /** @@ -109,7 +118,7 @@ class PasswordForm extends React.Component { <> this.input = el} + ref={el => this.inputPassword = el} label={this.props.translate('common.password')} secureTextEntry autoCompleteType={ComponentUtils.PASSWORD_AUTOCOMPLETE_TYPE} @@ -124,7 +133,7 @@ class PasswordForm extends React.Component { @@ -137,6 +146,7 @@ class PasswordForm extends React.Component { {this.props.account.requiresTwoFactorAuth && ( this.input2FA = el} label={this.props.translate('passwordForm.twoFactorCode')} value={this.state.twoFactorAuthCode} placeholder={this.props.translate('passwordForm.requiredWhen2FAEnabled')}