///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools // // Copyright (C) 2013 - 2024, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// import React, { useState } from 'react'; import LoginImage from '../../img/login.svg?svgr'; import { InputSelect, InputText, MESSAGE_TYPE, NotifierMessage } from '../components/FormComponents'; import BasePage, { SecurityButton } from './BasePage'; import { useDelayedCaller } from '../custom_hooks'; import gettext from 'sources/gettext'; import PropTypes from 'prop-types'; function EmailValidateView({mfaView, sendEmailUrl, csrfHeader, csrfToken}) { const [inputValue, setInputValue] = useState(''); const [error, setError] = useState(''); const [sentMessage, setSentMessage] = useState(''); const [sending, setSending] = useState(false); const [showResend, setShowResend] = useState(false); const showResendAfter = useDelayedCaller(()=>{ setShowResend(true); }); const sendCodeToEmail = ()=>{ setSending(true); let accept = 'text/html; charset=utf-8;'; fetch(sendEmailUrl, { method: 'POST', mode: 'cors', cache: 'no-cache', headers: { 'Accept': accept, 'Content-Type': 'application/json; charset=utf-8;', [csrfHeader]: csrfToken, }, redirect: 'follow' }).then((resp) => { if (!resp.ok) { resp.text().then(msg => setError(msg)); return; } return resp.json(); }).then((resp) => { if (!resp) return; setSentMessage(resp.message); showResendAfter(20000); }).finally(()=>{ setSending(false); }); }; return <>
{mfaView.description}
{sentMessage && <>
{sentMessage}
{showResend &&
{gettext('Haven\'t received an email?')} {gettext('Send again')}
} {gettext('Validate')} } {error && } {!sentMessage && {sending ? mfaView.button_label_sending : mfaView.button_label} } ; } EmailValidateView.propTypes = { mfaView: PropTypes.object, sendEmailUrl: PropTypes.string, csrfHeader: PropTypes.string, csrfToken: PropTypes.string }; function AuthenticatorValidateView({mfaView}) { const [inputValue, setInputValue] = useState(''); return <>
{mfaView.auth_description}
{gettext('Validate')} ; } AuthenticatorValidateView.propTypes = { mfaView: PropTypes.object, }; export default function MfaValidatePage({actionUrl, views, logoutUrl, sendEmailUrl, csrfHeader, csrfToken, ...props}) { const [method, setMethod] = useState(Object.values(views).find((v)=>v.selected)?.id); return ( } {...props}>
({ label: views[k].label, value: views[k].id, imageUrl: views[k].icon }))} onChange={setMethod} controlProps={{ allowClear: false, }} />
{method == 'email' && } {method == 'authenticator' && }
); } MfaValidatePage.propTypes = { actionUrl: PropTypes.string, views: PropTypes.object, logoutUrl: PropTypes.string, sendEmailUrl: PropTypes.string, csrfHeader: PropTypes.string, csrfToken: PropTypes.string };