Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,36 @@ <h4>Employee Master</h4>
color="accent"
class="mat_green"
(click)="activateDeactivate(element.userID, false)"
style="margin-right: 5px;"
>
Activate
</button>
<button
mat-raised-button
color="warn"
matTooltip="Unlock account locked due to failed login attempts"
(click)="unlockUserAccount(element.userID, element.userName)"
style="margin-right: 5px;"
>
Unlock
</button>
<button
*ngIf="element.deleted === false"
mat-raised-button
class="mat_blue"
color="primary"
(click)="activateDeactivate(element.userID, true)"
style="margin-right: 5px;"
>
Deactivate
</button>
<button
mat-icon-button
matTooltip="Check lock status"
(click)="checkUserLockStatus(element.userID)"
>
<mat-icon>info</mat-icon>
</button>
</td>
</ng-container>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,100 @@ export class EmployeeMasterNewComponent implements OnInit {
},
);
}

unlockUserAccount(userID: number, userName: string) {
this.dialogService
.confirm(
'Confirm Unlock',
`Are you sure you want to unlock the account for user "${userName}"? This will reset their failed login attempts and allow them to log in again.`,
)
.subscribe(
(res) => {
if (res) {
this.employeeMasterNewService.unlockUserAccount(userID).subscribe(
(response: any) => {
if (response && response.statusCode === 200) {
this.dialogService.alert(
'User account unlocked successfully. The user can now log in.',
'success',
);
this.getAllUserDetails();
this.searchTerm = null;
} else {
this.dialogService.alert(
response?.errorMessage || 'Failed to unlock user account',
'error',
);
}
},
(err) => {
console.log('error', err);
this.dialogService.alert(
'Error unlocking user account. Please try again.',
'error',
);
},
);
}
},
(err) => {
console.log(err);
},
);
}

checkUserLockStatus(userID: number) {
this.employeeMasterNewService.getUserLockStatus(userID).subscribe(
(response: any) => {
if (response && response.statusCode === 200) {
let data;
try {
data = JSON.parse(response.data);
} catch (e) {
console.error('Failed to parse lock status data:', e);
this.dialogService.alert(
'Invalid lock status data received. Please try again.',
'error',
);
return;
}
let message = '';
if (data.isLockedDueToFailedAttempts) {
message = `Account is LOCKED due to failed login attempts.\n\n` +
`Locked at: ${data.lockTimestamp}\n` +
`Failed attempts: ${data.failedAttempts}\n` +
`Time remaining: ${data.remainingTime}\n` +
(data.unlockTime ? `Auto-unlock at: ${data.unlockTime}\n` : '') +
`\nYou can unlock this account manually using the Unlock button.`;
} else if (data.lockExpired) {
message = `Account lock has EXPIRED.\n\n` +
`Original lock time: ${data.lockTimestamp}\n` +
`The account will automatically unlock when the user tries to log in.`;
} else if (data.isLocked) {
message = `Account is DEACTIVATED by administrator.\n\n` +
`Use the Activate button to reactivate this account.`;
} else {
message = `Account is ACTIVE.\n\n` +
`Failed login attempts: ${data.failedAttempts}`;
}
this.dialogService.alert(message, 'info');
} else {
this.dialogService.alert(
response?.errorMessage || 'Failed to get lock status',
'error',
);
}
},
(err) => {
console.log('error', err);
this.dialogService.alert(
'Error getting lock status. Please try again.',
'error',
);
},
);
}

filterComponentList(searchTerm?: string) {
if (!searchTerm) {
this.filteredsearchResult.data = this.searchResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,16 @@ export class EmployeeMasterNewServices {
// .map(this.extractData)
// .catch(this.handleError)
}

getUserLockStatus(userId: number): Observable<any> {
return this.http.post(environment.getUserLockStatusUrl, {
userId: userId,
});
}

unlockUserAccount(userId: number): Observable<any> {
return this.http.post(environment.unlockUserAccountUrl, {
userId: userId,
});
}
}
4 changes: 4 additions & 0 deletions src/app/user-login/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ export class loginContentClassComponent implements OnInit, OnDestroy {
this.loginservice.dologoutUsrFromPreSession(true);
}
});
} else {
this.alertMessage.alert(response.errorMessage, 'error');
}
}
},
Expand Down Expand Up @@ -282,6 +284,8 @@ export class loginContentClassComponent implements OnInit, OnDestroy {
this.loginservice.dologoutUsrFromPreSession(true);
}
});
} else {
this.alertMessage.alert(response.errorMessage, 'error');
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/environments/environment.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ export const environment = {
editUserDetailsUrl: `${adminBaseUrl}editUserDetails`,
userActivationDeactivationUrl: `${adminBaseUrl}deletedUserDetails`,
checkEmpIdAvailabilityUrl: `${adminBaseUrl}m/FindEmployeeDetails`,

// User Account Lock Management APIs (Common-API)
getUserLockStatusUrl: `${commonBaseURL}user/getUserLockStatus`,
unlockUserAccountUrl: `${commonBaseURL}user/unlockUserAccount`,

getStates_url: `${adminBaseUrl}m/role/state`,
getDistricts_url: `${adminBaseUrl}m/location/findDistrict`,
getServiceLines_url: `${adminBaseUrl}m/role/service`,
Expand Down
5 changes: 5 additions & 0 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ export const environment = {
editUserDetailsUrl: `${adminBaseUrl}editUserDetails`,
userActivationDeactivationUrl: `${adminBaseUrl}deletedUserDetails`,
checkEmpIdAvailabilityUrl: `${adminBaseUrl}m/FindEmployeeDetails`,

// User Account Lock Management APIs (Common-API)
getUserLockStatusUrl: `${commonBaseURL}user/getUserLockStatus`,
unlockUserAccountUrl: `${commonBaseURL}user/unlockUserAccount`,

getStates_url: `${adminBaseUrl}m/role/state`,
getDistricts_url: `${adminBaseUrl}m/location/findDistrict`,
getServiceLines_url: `${adminBaseUrl}m/role/service`,
Expand Down
5 changes: 5 additions & 0 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ export const environment = {
editUserDetailsUrl: `${adminBaseUrl}editUserDetails`,
userActivationDeactivationUrl: `${adminBaseUrl}deletedUserDetails`,
checkEmpIdAvailabilityUrl: `${adminBaseUrl}m/FindEmployeeDetails`,

// User Account Lock Management APIs (Common-API)
getUserLockStatusUrl: `${commonBaseURL}user/getUserLockStatus`,
unlockUserAccountUrl: `${commonBaseURL}user/unlockUserAccount`,

getStates_url: `${adminBaseUrl}m/role/state`,
getDistricts_url: `${adminBaseUrl}m/location/findDistrict`,
getServiceLines_url: `${adminBaseUrl}m/role/service`,
Expand Down