Skip to content

Commit

Permalink
Merge pull request #374 from DHI/sude/auth
Browse files Browse the repository at this point in the history
Change Password Requirement for IEC Security
  • Loading branch information
sude-dewi authored Aug 13, 2024
2 parents 3fea191 + b9ba4aa commit 075cd52
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.8.53",
"version": "0.8.54",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
17 changes: 10 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,7 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele
const [deletedDialog, setDeletedDialog] = useState(false);
const [deleteRow, setDeleteRow] = useState({});
const [filteringColumnExtensions, setFilteringColumnExtensions] = useState([]);
const [errorMessage, setErrorMessage] = useState('');
const getRowId = (row) => row.id;

const metadataHeader = metadata
Expand Down Expand Up @@ -129,21 +130,22 @@ 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);
setErrorMessage('Passwords must be at least 7 characters');
console.log('Update Account: ', error);
}
);
}
Expand Down Expand Up @@ -202,6 +204,7 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele
onSave={handleSubmit}
hasPassword
userGroupsDefaultSelected={userGroupsDefaultSelected}
errorMessage={errorMessage}
/>
<Toolbar />
<TableColumnVisibility />
Expand Down
11 changes: 8 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,7 @@ const Popup: React.FC<PopupProps> = ({
metadata,
hasPassword,
userGroupsDefaultSelected,
errorMessage,
}) => {
const [error, setError] = useState<boolean>(false);
const [passwordStrengthColor, setPasswordStrengthColor] = useState('red');
Expand Down Expand Up @@ -141,7 +142,8 @@ const Popup: React.FC<PopupProps> = ({
variant="standard"
required={isNew}
value={row.password || ''}
error={!passwordValid}
error={!passwordValid || errorMessage!==''}
helperText={errorMessage}
InputProps={{ endAdornment }}
onChange={onChange}
autoComplete="new-password"
Expand All @@ -156,9 +158,12 @@ const Popup: React.FC<PopupProps> = ({
required={isNew}
label="Repeat Password"
value={row.repeatPassword || ''}
error={!passwordValid}
error={!passwordValid || errorMessage!==''}
onChange={onChange}
helperText={!passwordValid && 'Passwords do not match'}
helperText={
(!passwordValid && 'Passwords do not match') ||
errorMessage
}
autoComplete="new-password"
/>
</>
Expand Down
4 changes: 3 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,7 @@ const PopupEditing = React.memo(
onSave,
hasPassword,
userGroupsDefaultSelected,
errorMessage,
}: PopupEditingProps) => (
<Plugin>
<Template name="popupEditing">
Expand Down Expand Up @@ -141,7 +142,7 @@ const PopupEditing = React.memo(
}
};

const open = editingRowIds.length > 0 || isNew;
const open = editingRowIds.length > 0 || isNew || errorMessage!=='';

return (
<Popup
Expand All @@ -160,6 +161,7 @@ const PopupEditing = React.memo(
metadata={metadata}
hasPassword={hasPassword}
userGroupsDefaultSelected={userGroupsDefaultSelected}
errorMessage={errorMessage}
/>
);
}}
Expand Down
2 changes: 2 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,7 @@ export interface PopupEditingProps {
* Set User Groups default list when creating a new Account
*/
userGroupsDefaultSelected?: string[];
errorMessage?: string;
}

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

export interface MetadataEditorProps {
Expand Down

0 comments on commit 075cd52

Please sign in to comment.