|
|
|
@ -97,53 +97,158 @@ public class OfficialAPIService { |
|
|
|
return Collections.singletonList(successResponse); |
|
|
|
} |
|
|
|
|
|
|
|
// @Transactional |
|
|
|
// public List<Map<String, Object>> getloginList(String username, String password, String usertype) { |
|
|
|
// // PIN added in response for session logout needed by vaibalan |
|
|
|
// String sqlQuery = ""; |
|
|
|
// List<Map<String, Object>> result = null; |
|
|
|
// try { |
|
|
|
// switch (usertype) { |
|
|
|
// case "erp": |
|
|
|
// // sqlQuery = "SELECT * FROM `EG_USER` WHERE `ISPORTALUSER` <> 1 AND `ISACTIVE` |
|
|
|
// // = 1 AND `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1"; |
|
|
|
// sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
// result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
// break; |
|
|
|
// case "nonerp": |
|
|
|
// sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
// result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
// break; |
|
|
|
// // additional cases can be added here |
|
|
|
// default: |
|
|
|
// sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
// result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
// // result = Collections.emptyList(); |
|
|
|
// break; |
|
|
|
// } |
|
|
|
// } catch (Exception e) { |
|
|
|
// // Log the error |
|
|
|
// e.printStackTrace(); |
|
|
|
// // Return an error message as part of the result list |
|
|
|
// return Collections |
|
|
|
// .singletonList(Collections.singletonMap("error", "An error occurred while fetching data.")); |
|
|
|
// } |
|
|
|
|
|
|
|
// // If no records found, return a status and message indicating no user found |
|
|
|
// if (result == null || result.isEmpty()) { |
|
|
|
// Map<String, Object> response = Map.of( |
|
|
|
// "status", 404, |
|
|
|
// "message", "User not found."); |
|
|
|
// return Collections.singletonList(response); |
|
|
|
// } |
|
|
|
|
|
|
|
// // Add a success status and message to the result |
|
|
|
// Map<String, Object> successResponse = Map.of( |
|
|
|
// "status", 200, |
|
|
|
// "message", "login successfuly.", |
|
|
|
// "data", result); |
|
|
|
// return Collections.singletonList(successResponse); |
|
|
|
// } |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public List<Map<String, Object>> getloginList(String username, String password, String usertype) { |
|
|
|
public List<Map<String, Object>> getloginList(String username, String password, String usertype, String deviceid) { |
|
|
|
// PIN added in response for session logout needed by vaibalan |
|
|
|
String sqlQuery = ""; |
|
|
|
List<Map<String, Object>> result = null; |
|
|
|
List<Map<String, Object>> result=null; |
|
|
|
try { |
|
|
|
switch (usertype) { |
|
|
|
case "erp": |
|
|
|
// sqlQuery = "SELECT * FROM `EG_USER` WHERE `ISPORTALUSER` <> 1 AND `ISACTIVE` |
|
|
|
// = 1 AND `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1"; |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
break; |
|
|
|
case "nonerp": |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
break; |
|
|
|
// additional cases can be added here |
|
|
|
default: |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
// result = Collections.emptyList(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
// Log the error |
|
|
|
e.printStackTrace(); |
|
|
|
// Return an error message as part of the result list |
|
|
|
return Collections |
|
|
|
.singletonList(Collections.singletonMap("error", "An error occurred while fetching data.")); |
|
|
|
} |
|
|
|
|
|
|
|
// If no records found, return a status and message indicating no user found |
|
|
|
if (result == null || result.isEmpty()) { |
|
|
|
Map<String, Object> response = Map.of( |
|
|
|
"status", 404, |
|
|
|
"message", "User not found."); |
|
|
|
return Collections.singletonList(response); |
|
|
|
} |
|
|
|
|
|
|
|
// Add a success status and message to the result |
|
|
|
Map<String, Object> successResponse = Map.of( |
|
|
|
"status", 200, |
|
|
|
"message", "login successfuly.", |
|
|
|
"data", result); |
|
|
|
return Collections.singletonList(successResponse); |
|
|
|
} |
|
|
|
switch (usertype) { |
|
|
|
case "erp": |
|
|
|
//sqlQuery = "SELECT * FROM `EG_USER` WHERE `ISPORTALUSER` <> 1 AND `ISACTIVE` = 1 AND `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1"; |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN, deviceid, issecure FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
break; |
|
|
|
case "nonerp": |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN, deviceid, issecure FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
break; |
|
|
|
// additional cases can be added here |
|
|
|
default: |
|
|
|
sqlQuery = "SELECT id, USER_NAME, EXTRAFIELD2, PIN, deviceid, issecure FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1"; |
|
|
|
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); |
|
|
|
//result = Collections.emptyList(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
// Log the error |
|
|
|
e.printStackTrace(); |
|
|
|
// Return an error message as part of the result list |
|
|
|
return Collections.singletonList(Collections.singletonMap("error", "An error occurred while fetching data.")); |
|
|
|
} |
|
|
|
|
|
|
|
// If no records found, return a status and message indicating no user found |
|
|
|
if (result == null || result.isEmpty()) { |
|
|
|
Map<String, Object> response = Map.of( |
|
|
|
"status", 404, |
|
|
|
"message", "User not found." |
|
|
|
); |
|
|
|
return Collections.singletonList(response); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DEVICE SECURITY CHECK |
|
|
|
Map<String, Object> user = result.get(0); |
|
|
|
|
|
|
|
Object isSecureObject = user.get("issecure"); |
|
|
|
Object storedDeviceObject = user.get("deviceid"); |
|
|
|
|
|
|
|
boolean isSecure = |
|
|
|
isSecureObject != null && |
|
|
|
( |
|
|
|
Boolean.TRUE.equals(isSecureObject) || |
|
|
|
"1".equals(String.valueOf(isSecureObject)) || |
|
|
|
"true".equalsIgnoreCase(String.valueOf(isSecureObject)) |
|
|
|
); |
|
|
|
|
|
|
|
String storedDeviceId = |
|
|
|
storedDeviceObject == null |
|
|
|
? null |
|
|
|
: String.valueOf(storedDeviceObject); |
|
|
|
|
|
|
|
if (isSecure) { |
|
|
|
|
|
|
|
// Device ID is mandatory for secure users |
|
|
|
if (deviceid == null || deviceid.trim().isEmpty()) { |
|
|
|
|
|
|
|
Map<String, Object> response = Map.of( |
|
|
|
"status", 403, |
|
|
|
"message", "Device ID is required for this user." |
|
|
|
); |
|
|
|
|
|
|
|
return Collections.singletonList(response); |
|
|
|
} |
|
|
|
|
|
|
|
// Stored device ID is missing |
|
|
|
if (storedDeviceId == null || storedDeviceId.trim().isEmpty()) { |
|
|
|
|
|
|
|
Map<String, Object> response = Map.of( |
|
|
|
"status", 403, |
|
|
|
"message", "No device is registered for this user." |
|
|
|
); |
|
|
|
|
|
|
|
return Collections.singletonList(response); |
|
|
|
} |
|
|
|
|
|
|
|
// Device ID doesn't match |
|
|
|
if (!storedDeviceId.equals(deviceid.trim())) { |
|
|
|
|
|
|
|
Map<String, Object> response = Map.of( |
|
|
|
"status", 403, |
|
|
|
"message", "Device ID does not match the registered device." |
|
|
|
); |
|
|
|
|
|
|
|
return Collections.singletonList(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// LOGIN SUCCESS |
|
|
|
// Add a success status and message to the result |
|
|
|
Map<String, Object> successResponse = Map.of( |
|
|
|
"status", 200, |
|
|
|
"message", "login successfuly.", |
|
|
|
"data", result |
|
|
|
); |
|
|
|
return Collections.singletonList(successResponse); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public List<UpdateResponse> updatePassword(String username, String password) { |
|
|
|
|