@@ -1230,4 +1230,42 @@ public ResponseEntity<?> getUserDetails(@PathVariable("userName") String userNam
12301230 }
12311231
12321232 }
1233+
1234+ @ Operation (summary = "Unlock user account locked due to failed login attempts" )
1235+ @ RequestMapping (value = "/unlockUserAccount" , method = RequestMethod .POST , produces = MediaType .APPLICATION_JSON , headers = "Authorization" )
1236+ public String unlockUserAccount (@ RequestBody String request ) {
1237+ OutputResponse response = new OutputResponse ();
1238+ try {
1239+ Long userId = parseUserIdFromRequest (request );
1240+ boolean unlocked = iemrAdminUserServiceImpl .unlockUserAccount (userId );
1241+ response .setResponse (unlocked ? "User account successfully unlocked" : "User account was not locked" );
1242+ } catch (Exception e ) {
1243+ logger .error ("Error unlocking user account: " + e .getMessage (), e );
1244+ response .setError (e );
1245+ }
1246+ return response .toString ();
1247+ }
1248+
1249+ @ Operation (summary = "Get user account lock status" )
1250+ @ RequestMapping (value = "/getUserLockStatus" , method = RequestMethod .POST , produces = MediaType .APPLICATION_JSON , headers = "Authorization" )
1251+ public String getUserLockStatus (@ RequestBody String request ) {
1252+ OutputResponse response = new OutputResponse ();
1253+ try {
1254+ Long userId = parseUserIdFromRequest (request );
1255+ String lockStatusJson = iemrAdminUserServiceImpl .getUserLockStatusJson (userId );
1256+ response .setResponse (lockStatusJson );
1257+ } catch (Exception e ) {
1258+ logger .error ("Error getting user lock status: " + e .getMessage (), e );
1259+ response .setError (e );
1260+ }
1261+ return response .toString ();
1262+ }
1263+
1264+ private Long parseUserIdFromRequest (String request ) throws IEMRException {
1265+ JsonObject requestObj = JsonParser .parseString (request ).getAsJsonObject ();
1266+ if (!requestObj .has ("userId" ) || requestObj .get ("userId" ).isJsonNull ()) {
1267+ throw new IEMRException ("userId is required" );
1268+ }
1269+ return requestObj .get ("userId" ).getAsLong ();
1270+ }
12331271}
0 commit comments