|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
import {
|
|
import {
|
|
|
- Modal, ModalHeader, ModalBody, ModalFooter,
|
|
|
|
|
|
|
+ Modal, ModalHeader, ModalBody, ModalFooter, Collapse,
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
|
|
|
|
|
import { apiv3Put } from '~/client/util/apiv3-client';
|
|
import { apiv3Put } from '~/client/util/apiv3-client';
|
|
@@ -21,25 +21,18 @@ class PasswordResetModal extends React.Component {
|
|
|
isPasswordResetDone: false,
|
|
isPasswordResetDone: false,
|
|
|
sendEmail: false,
|
|
sendEmail: false,
|
|
|
isCreateUserButtonPushed: false,
|
|
isCreateUserButtonPushed: false,
|
|
|
|
|
+ collapse: false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
this.resetPassword = this.resetPassword.bind(this);
|
|
this.resetPassword = this.resetPassword.bind(this);
|
|
|
- this.handleCheckBox = this.handleCheckBox.bind(this);
|
|
|
|
|
|
|
+ this.toggle = this.toggle.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async resetPassword() {
|
|
async resetPassword() {
|
|
|
const { t, userForPasswordResetModal } = this.props;
|
|
const { t, userForPasswordResetModal } = this.props;
|
|
|
try {
|
|
try {
|
|
|
const res = await apiv3Put('/users/reset-password', { id: userForPasswordResetModal._id });
|
|
const res = await apiv3Put('/users/reset-password', { id: userForPasswordResetModal._id });
|
|
|
- const { newPassword, failedToSendEmail } = res.data;
|
|
|
|
|
- if (failedToSendEmail == null) {
|
|
|
|
|
- const msg = `Email has been sent<br>・${userForPasswordResetModal.email}`;
|
|
|
|
|
- toastSuccess(msg);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- const msg = { message: `email: ${failedToSendEmail.email}<br>reason: ${failedToSendEmail.reason}` };
|
|
|
|
|
- toastError(msg);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const { newPassword } = res.data;
|
|
|
this.setState({ temporaryPassword: newPassword, isPasswordResetDone: true });
|
|
this.setState({ temporaryPassword: newPassword, isPasswordResetDone: true });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
@@ -47,6 +40,10 @@ class PasswordResetModal extends React.Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ toggle() {
|
|
|
|
|
+ this.setState({ collapse: !this.state.collapse });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
renderModalBodyBeforeReset() {
|
|
renderModalBodyBeforeReset() {
|
|
|
const { t, userForPasswordResetModal } = this.props;
|
|
const { t, userForPasswordResetModal } = this.props;
|
|
|
|
|
|
|
@@ -73,7 +70,17 @@ class PasswordResetModal extends React.Component {
|
|
|
{t('user_management.reset_password_modal.target_user')}: <code>{userForPasswordResetModal.email}</code>
|
|
{t('user_management.reset_password_modal.target_user')}: <code>{userForPasswordResetModal.email}</code>
|
|
|
</p>
|
|
</p>
|
|
|
<p>
|
|
<p>
|
|
|
- {t('user_management.reset_password_modal.new_password')}: <code>{this.state.temporaryPassword}</code>
|
|
|
|
|
|
|
+ {t('user_management.reset_password_modal.new_password')}:
|
|
|
|
|
+ <button className="btn btn-secondary mx-2 px-1 py-0" size="sm" onClick={this.toggle} aria-expanded="false">
|
|
|
|
|
+ {this.state.collapse ? t('user_management.reset_password_modal.hide_password') : t('user_management.reset_password_modal.show_password') }
|
|
|
|
|
+ </button>
|
|
|
|
|
+ {this.state.collapse && (
|
|
|
|
|
+ <Collapse isOpen={this.state.collapse}>
|
|
|
|
|
+ <code>
|
|
|
|
|
+ {this.state.temporaryPassword}
|
|
|
|
|
+ </code>
|
|
|
|
|
+ </Collapse>
|
|
|
|
|
+ )}
|
|
|
</p>
|
|
</p>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
@@ -82,32 +89,9 @@ class PasswordResetModal extends React.Component {
|
|
|
returnModalFooterBeforeReset() {
|
|
returnModalFooterBeforeReset() {
|
|
|
const { t, isMailerSetup } = this.props;
|
|
const { t, isMailerSetup } = this.props;
|
|
|
return (
|
|
return (
|
|
|
- <>
|
|
|
|
|
- <div className="col text-left custom-control custom-checkbox custom-checkbox-info text-left" onChange={this.handleCheckBox}>
|
|
|
|
|
- <input
|
|
|
|
|
- type="checkbox"
|
|
|
|
|
- id="sendEmail"
|
|
|
|
|
- className="custom-control-input"
|
|
|
|
|
- name="sendEmail"
|
|
|
|
|
- defaultChecked={this.state.sendEmail}
|
|
|
|
|
- disabled={!isMailerSetup}
|
|
|
|
|
- />
|
|
|
|
|
- <label className="custom-control-label" htmlFor="sendEmail">
|
|
|
|
|
- {t('admin:user_management.reset_password_modal.send_password_email')}
|
|
|
|
|
- </label>
|
|
|
|
|
- {isMailerSetup
|
|
|
|
|
- // eslint-disable-next-line react/no-danger
|
|
|
|
|
- ? <p className="form-text text-muted" dangerouslySetInnerHTML={{ __html: t('admin:user_management.reset_password_modal.mail_setting_link') }} />
|
|
|
|
|
- // eslint-disable-next-line react/no-danger
|
|
|
|
|
- : <p className="form-text text-muted" dangerouslySetInnerHTML={{ __html: t('admin:mailer_setup_required') }} />
|
|
|
|
|
- }
|
|
|
|
|
- </div>
|
|
|
|
|
- <div>
|
|
|
|
|
- <button type="submit" className="btn btn-danger" onClick={this.resetPassword}>
|
|
|
|
|
- {t('user_management.reset_password')}
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
- </>
|
|
|
|
|
|
|
+ <button type="submit" className="btn btn-danger" onClick={this.resetPassword}>
|
|
|
|
|
+ {t('user_management.reset_password')}
|
|
|
|
|
+ </button>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|