codekingpro/portable-devtools
114k
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9 10import { makeStyles } from '@mui/styles';11import React from 'react';12import PropTypes from 'prop-types';13import gettext from 'sources/gettext';14import BaseUISchema from '../SchemaView/base_schema.ui';15import SchemaView from '../SchemaView';16 17class ChangePasswordSchema extends BaseUISchema {18 constructor(user, isPgpassFileUsed, hasCsrfToken=false, showUser=true) {19 super({20 user: user,21 password: '',22 newPassword: '',23 confirmPassword: ''24 });25 this.isPgpassFileUsed = isPgpassFileUsed;26 this.hasCsrfToken = hasCsrfToken;27 this.showUser = showUser;28 }29 30 get baseFields() {31 let self = this;32 return [33 {34 id: 'user', label: gettext('User'), type: 'text', disabled: true, visible: this.showUser35 }, {36 id: 'password', label: gettext('Current Password'), type: 'password',37 disabled: self.isPgpassFileUsed, noEmpty: !self.isPgpassFileUsed,38 controlProps: {39 maxLength: null,40 autoComplete: 'new-password'41 }42 }, {43 id: 'newPassword', label: gettext('New Password'), type: 'password',44 noEmpty: true,45 controlProps: {46 maxLength: null47 }48 }, {49 id: 'confirmPassword', label: gettext('Confirm Password'), type: 'password',50 noEmpty: true,51 controlProps: {52 maxLength: null53 }54 }55 ].concat(this.hasCsrfToken ? [56 {57 id: 'csrf_token', visible: false, type: 'text'58 }59 ]: []);60 }61 62 validate(state, setError) {63 let errmsg = null;64 if (state.newPassword !== state.confirmPassword) {65 errmsg = gettext('Passwords do not match.');66 setError('confirmPassword', errmsg);67 return true;68 } else {69 setError('confirmPassword', null);70 }71 72 return false;73 }74}75 76const useStyles = makeStyles((theme)=>({77 root: {78 ...theme.mixins.tabPanel,79 },80}));81 82export default function ChangePasswordContent({getInitData=() => { /*This is intentional (SonarQube)*/ },83 onSave, onClose, hasCsrfToken=false, showUser=true}) {84 const classes = useStyles();85 86 return<SchemaView87 formType={'dialog'}88 getInitData={getInitData}89 schema={new ChangePasswordSchema('', false, hasCsrfToken, showUser)}90 viewHelperProps={{91 mode: 'create',92 }}93 customSaveBtnName={'Change'}94 onSave={onSave}95 onClose={onClose}96 hasSQL={false}97 disableSqlHelp={true}98 disableDialogHelp={true}99 isTabView={false}100 formClassName={classes.root}101 />;102}103ChangePasswordContent.propTypes = {104 onSave: PropTypes.func,105 onClose: PropTypes.func,106 getInitData: PropTypes.func,107 hasCsrfToken: PropTypes.bool,108 showUser: PropTypes.bool109};110 