Skip to content

Commit

Permalink
Add SMTP check for reset password link (#5303)
Browse files Browse the repository at this point in the history
* Add SMTP check for reset password link

* Add redirect to /forget_password
  • Loading branch information
scouillard authored Jul 5, 2023
1 parent 8ddfb4b commit 397f9be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/api/v1/env_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def index
OPENID_CONNECT: ENV['OPENID_CONNECT_ISSUER'].present?,
HCAPTCHA_KEY: ENV.fetch('HCAPTCHA_SITE_KEY', nil),
VERSION_TAG: ENV.fetch('VERSION_TAG', ''),
CURRENT_PROVIDER: current_provider
CURRENT_PROVIDER: current_provider,
SMTP_ENABLED: ENV.fetch('SMTP_SERVER', nil)
}, status: :ok
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import useCreateSession from '../../../../hooks/mutations/sessions/useCreateSess
import useSignInForm from '../../../../hooks/forms/users/authentication/useSignInForm';
import HCaptcha from '../../../shared_components/utilities/HCaptcha';
import FormCheckBox from '../../../shared_components/forms/controls/FormCheckBox';
import useEnv from '../../../../hooks/queries/env/useEnv';

export default function SigninForm() {
const { t } = useTranslation();
const { methods, fields } = useSignInForm();
const createSessionAPI = useCreateSession();
const captchaRef = useRef(null);
const { data: env } = useEnv();

const handleSubmit = useCallback(async (session) => {
const results = await captchaRef.current?.execute({ async: true });
Expand All @@ -52,7 +54,11 @@ export default function SigninForm() {
<FormCheckBox field={fields.extend_session} />
</Col>
<Col>
<Link to="/forget_password" className="text-link float-end small"> {t('authentication.forgot_password')} </Link>
{
env?.SMTP_ENABLED && (
<Link to="/forget_password" className="text-link float-end small"> {t('authentication.forgot_password')} </Link>
)
}
</Col>
</Row>
<HCaptcha ref={captchaRef} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@

import React from 'react';
import Card from 'react-bootstrap/Card';
import { Link } from 'react-router-dom';
import { Link, Navigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import ForgetPwdForm from './forms/ForgetPwdForm';
import Logo from '../../shared_components/Logo';
import useEnv from '../../../hooks/queries/env/useEnv';

export default function ForgetPassword() {
const { t } = useTranslation();
const { data: env, isLoading } = useEnv();

if (isLoading) return null;

if (!env?.SMTP_ENABLED) {
return <Navigate to="/" />;
}

return (
<div className="vertical-center">
Expand Down

0 comments on commit 397f9be

Please sign in to comment.