2022-07-11 03:09:09 -05:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import gettext from 'sources/gettext';
|
2022-08-05 03:35:53 -05:00
|
|
|
import BaseUISchema from '../SchemaView/base_schema.ui';
|
|
|
|
import SchemaView from '../SchemaView';
|
2022-07-11 03:09:09 -05:00
|
|
|
|
|
|
|
class ChangePasswordSchema extends BaseUISchema {
|
2023-06-30 05:38:33 -05:00
|
|
|
constructor(user, isPgpassFileUsed, hasCsrfToken=false, showUser=true) {
|
2022-07-11 03:09:09 -05:00
|
|
|
super({
|
|
|
|
user: user,
|
|
|
|
password: '',
|
|
|
|
newPassword: '',
|
|
|
|
confirmPassword: ''
|
|
|
|
});
|
|
|
|
this.isPgpassFileUsed = isPgpassFileUsed;
|
2023-06-30 05:38:33 -05:00
|
|
|
this.hasCsrfToken = hasCsrfToken;
|
|
|
|
this.showUser = showUser;
|
2022-07-11 03:09:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
get baseFields() {
|
|
|
|
let self = this;
|
|
|
|
return [
|
|
|
|
{
|
2023-06-30 05:38:33 -05:00
|
|
|
id: 'user', label: gettext('User'), type: 'text', disabled: true, visible: this.showUser
|
2022-07-11 03:09:09 -05:00
|
|
|
}, {
|
|
|
|
id: 'password', label: gettext('Current Password'), type: 'password',
|
2024-04-08 06:49:51 -05:00
|
|
|
disabled: self.isPgpassFileUsed, noEmpty: !self.isPgpassFileUsed,
|
2022-07-11 03:09:09 -05:00
|
|
|
controlProps: {
|
2024-04-24 00:57:08 -05:00
|
|
|
maxLength: null,
|
|
|
|
autoComplete: 'new-password'
|
2022-07-11 03:09:09 -05:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
id: 'newPassword', label: gettext('New Password'), type: 'password',
|
|
|
|
noEmpty: true,
|
|
|
|
controlProps: {
|
|
|
|
maxLength: null
|
|
|
|
}
|
2023-06-30 05:38:33 -05:00
|
|
|
}, {
|
2022-07-11 03:09:09 -05:00
|
|
|
id: 'confirmPassword', label: gettext('Confirm Password'), type: 'password',
|
|
|
|
noEmpty: true,
|
|
|
|
controlProps: {
|
|
|
|
maxLength: null
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 05:38:33 -05:00
|
|
|
].concat(this.hasCsrfToken ? [
|
|
|
|
{
|
|
|
|
id: 'csrf_token', visible: false, type: 'text'
|
|
|
|
}
|
|
|
|
]: []);
|
2022-07-11 03:09:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
validate(state, setError) {
|
|
|
|
let errmsg = null;
|
|
|
|
if (state.newPassword !== state.confirmPassword) {
|
|
|
|
errmsg = gettext('Passwords do not match.');
|
|
|
|
setError('confirmPassword', errmsg);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
setError('confirmPassword', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 05:38:33 -05:00
|
|
|
export default function ChangePasswordContent({getInitData=() => { /*This is intentional (SonarQube)*/ },
|
|
|
|
onSave, onClose, hasCsrfToken=false, showUser=true}) {
|
2024-09-15 13:34:37 -05:00
|
|
|
const schema=React.useRef(null);
|
|
|
|
if (!schema.current)
|
|
|
|
schema.current = new ChangePasswordSchema(
|
|
|
|
'', false, hasCsrfToken, showUser
|
|
|
|
);
|
|
|
|
|
2024-06-17 05:15:40 -05:00
|
|
|
return <SchemaView
|
2022-07-11 03:09:09 -05:00
|
|
|
formType={'dialog'}
|
2023-06-30 05:38:33 -05:00
|
|
|
getInitData={getInitData}
|
2024-09-15 13:34:37 -05:00
|
|
|
schema={schema.current}
|
2022-07-11 03:09:09 -05:00
|
|
|
viewHelperProps={{
|
|
|
|
mode: 'create',
|
|
|
|
}}
|
2022-08-05 03:35:53 -05:00
|
|
|
customSaveBtnName={'Change'}
|
2022-07-11 03:09:09 -05:00
|
|
|
onSave={onSave}
|
|
|
|
onClose={onClose}
|
|
|
|
hasSQL={false}
|
|
|
|
disableSqlHelp={true}
|
|
|
|
disableDialogHelp={true}
|
|
|
|
isTabView={false}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
ChangePasswordContent.propTypes = {
|
|
|
|
onSave: PropTypes.func,
|
|
|
|
onClose: PropTypes.func,
|
2023-06-30 05:38:33 -05:00
|
|
|
getInitData: PropTypes.func,
|
|
|
|
hasCsrfToken: PropTypes.bool,
|
|
|
|
showUser: PropTypes.bool
|
2022-07-11 03:09:09 -05:00
|
|
|
};
|