///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools // // Copyright (C) 2013 - 2024, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// import React, { useState, useRef, useEffect } from 'react'; import PropTypes from 'prop-types'; import gettext from 'sources/gettext'; import url_for from 'sources/url_for'; import { Box } from '@mui/material'; import CloseIcon from '@mui/icons-material/CloseRounded'; import DeleteForeverIcon from '@mui/icons-material/DeleteForever'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import HelpIcon from '@mui/icons-material/Help'; import { DefaultButton, PrimaryButton, PgIconButton } from '../components/Buttons'; import { FormFooterMessage, FormNote, InputText, MESSAGE_TYPE } from '../components/FormComponents'; import { ModalContent, ModalFooter } from '../../../static/js/components/ModalContent'; export default function MasterPasswordContent({ closeModal, onResetPassowrd, onOK, onCancel, setHeight, isPWDPresent, data, keyringName}) { const containerRef = useRef(); const firstEleRef = useRef(); const okBtnRef = useRef(); const isKeyring = keyringName.length > 0; const [formData, setFormData] = useState({ password: '' }); const onTextChange = (e, id) => { let val = e; if (e?.target) { val = e.target.value; } setFormData((prev) => ({ ...prev, [id]: val })); }; const onKeyDown = (e) => { // If enter key is pressed then click on OK button if (e.key === 'Enter') { okBtnRef.current?.click(); } }; useEffect(() => { setTimeout(() => { firstEleRef.current?.focus(); }, 350); }, [firstEleRef.current]); useEffect(() => { setHeight?.(containerRef.current?.offsetHeight); }, [containerRef.current]); return ( {isKeyring ? {gettext('Please enter your master password.')}
onTextChange(e, 'password')} onKeyDown={(e) => onKeyDown(e)}/>
: {isPWDPresent ? gettext('Please enter your master password.') : gettext('Please set a master password for pgAdmin.')}
{isPWDPresent ? gettext('This is required to unlock saved passwords and reconnect to the database server(s).') : gettext('This will be used to secure and later unlock saved passwords and other credentials.')}
onTextChange(e, 'password')} onKeyDown={(e) => onKeyDown(e)} controlProps={{autoComplete: 'new-password'}}/>
} } onClick={() => { let _url = url_for('help.static', { 'filename': 'master_password.html', }); window.open(_url, 'pgadmin_help'); }} > {isPWDPresent && } onClick={() => {onResetPassowrd?.(isKeyring);}} > {gettext('Reset Master Password')} } { !isKeyring && } onClick={() => { onCancel?.(); closeModal(); }} >{gettext('Cancel')} } } disabled={formData.password.length == 0} onClick={() => { let postFormData = new FormData(); postFormData.append('password', formData.password); postFormData.append('submit_password', true); onOK?.(postFormData); closeModal(); }} > {gettext('OK')}
); } MasterPasswordContent.propTypes = { closeModal: PropTypes.func, onResetPassowrd: PropTypes.func, onOK: PropTypes.func, onCancel: PropTypes.func, setHeight: PropTypes.func, isPWDPresent: PropTypes.bool, data: PropTypes.object, keyringName: PropTypes.string, };