Skip to content

Commit

Permalink
Change Password Requirement for IEC Security
Browse files Browse the repository at this point in the history
  • Loading branch information
sude-dewi committed Aug 12, 2024
1 parent 3fea191 commit fa2d847
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
20 changes: 13 additions & 7 deletions packages/react-components/src/Accounts/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele
const [deletedDialog, setDeletedDialog] = useState(false);
const [deleteRow, setDeleteRow] = useState({});
const [filteringColumnExtensions, setFilteringColumnExtensions] = useState([]);
const [error, setError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const getRowId = (row) => row.id;

const metadataHeader = metadata
Expand Down Expand Up @@ -129,21 +131,23 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele

const handleSubmit = (row, isNew = false) => {
if (isNew) {
return (
createAccount(host, token, { ...row }).subscribe(() => {
return createAccount(host, token, { ...row }).subscribe(
() => {
fetchData();
}),
},
(error) => {
console.log('Create Account: ', error);
}
);
} else {
return (
updateAccount(host, token, { ...row }).subscribe(() => {
return updateAccount(host, token, { ...row }).subscribe(
() => {
fetchData();
}),
},
(error) => {
console.log('Update Accounts: ', error);
setError(true);
setErrorMessage('Passwords must be at least 7 characters');
console.log('Update Account: ', error);
}
);
}
Expand Down Expand Up @@ -202,6 +206,8 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele
onSave={handleSubmit}
hasPassword
userGroupsDefaultSelected={userGroupsDefaultSelected}
errorAccount={error}
errorMessage={errorMessage}
/>
<Toolbar />
<TableColumnVisibility />
Expand Down
12 changes: 9 additions & 3 deletions packages/react-components/src/common/Table/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const Popup: React.FC<PopupProps> = ({
metadata,
hasPassword,
userGroupsDefaultSelected,
errorMessage,
errorAccount,
}) => {
const [error, setError] = useState<boolean>(false);
const [passwordStrengthColor, setPasswordStrengthColor] = useState('red');
Expand Down Expand Up @@ -141,7 +143,8 @@ const Popup: React.FC<PopupProps> = ({
variant="standard"
required={isNew}
value={row.password || ''}
error={!passwordValid}
error={!passwordValid || errorAccount}
helperText={errorMessage}
InputProps={{ endAdornment }}
onChange={onChange}
autoComplete="new-password"
Expand All @@ -156,9 +159,12 @@ const Popup: React.FC<PopupProps> = ({
required={isNew}
label="Repeat Password"
value={row.repeatPassword || ''}
error={!passwordValid}
error={!passwordValid || errorAccount}
onChange={onChange}
helperText={!passwordValid && 'Passwords do not match'}
helperText={
(!passwordValid && 'Passwords do not match') ||
errorMessage
}
autoComplete="new-password"
/>
</>
Expand Down
6 changes: 5 additions & 1 deletion packages/react-components/src/common/Table/PopupEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const PopupEditing = React.memo(
onSave,
hasPassword,
userGroupsDefaultSelected,
errorAccount,
errorMessage,
}: PopupEditingProps) => (
<Plugin>
<Template name="popupEditing">
Expand Down Expand Up @@ -141,7 +143,7 @@ const PopupEditing = React.memo(
}
};

const open = editingRowIds.length > 0 || isNew;
const open = editingRowIds.length > 0 || isNew || errorAccount;

return (
<Popup
Expand All @@ -160,6 +162,8 @@ const PopupEditing = React.memo(
metadata={metadata}
hasPassword={hasPassword}
userGroupsDefaultSelected={userGroupsDefaultSelected}
errorMessage={errorMessage}
errorAccount={errorAccount}
/>
);
}}
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/src/common/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export interface PopupEditingProps {
* Set User Groups default list when creating a new Account
*/
userGroupsDefaultSelected?: string[];
errorAccount?: boolean;
errorMessage?: string;
}

export interface PopupProps {
Expand Down Expand Up @@ -142,6 +144,8 @@ export interface PopupProps {
* Set User Groups default list when creating a new Account
*/
userGroupsDefaultSelected?: string[];
errorAccount?: boolean;
errorMessage?: string;
}

export interface MetadataEditorProps {
Expand Down

0 comments on commit fa2d847

Please sign in to comment.