From 84a268701379541208a7e8a50b1db120644dae29 Mon Sep 17 00:00:00 2001 From: mohammedThaqi Date: Sat, 23 Mar 2024 15:28:38 +0530 Subject: [PATCH] login with original DB --- .idea/vcs.xml | 6 + pom.xml | 7 + .../lokshaba/component/UserSession.java | 97 ++++++----- .../component/UserSessionInterceptor.java | 4 +- .../lokshaba/controller/MainController.java | 40 +++-- .../controller/RestAPIController.java | 28 ++++ .../firstOrder/PollPersonalTrRepService.java | 62 +++++++ .../firstOrder/TrainingCenterRepService.java | 57 +++++++ .../election/pollingPersonal/firstOrder.html | 153 ++++++++++-------- .../lokshaba/LokshabaApplication.class | Bin 755 -> 1103 bytes .../lokshaba/component/UserSession.class | Bin 1755 -> 2363 bytes .../component/UserSessionInterceptor.class | Bin 2511 -> 2476 bytes .../lokshaba/configuration/WebConfig.class | Bin 1192 -> 1192 bytes .../lokshaba/controller/MainController.class | Bin 3362 -> 3786 bytes .../election/lokshaba/others/AppConfig.class | Bin 1383 -> 1383 bytes 15 files changed, 326 insertions(+), 128 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/com/election/lokshaba/controller/RestAPIController.java create mode 100644 src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/PollPersonalTrRepService.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index b61595f..deb1bc3 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,13 @@ mysql-connector-j runtime + + + com.oracle.database.jdbc + ojdbc8 + runtime + + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/election/lokshaba/component/UserSession.java b/src/main/java/com/election/lokshaba/component/UserSession.java index b45f530..30e3ff3 100644 --- a/src/main/java/com/election/lokshaba/component/UserSession.java +++ b/src/main/java/com/election/lokshaba/component/UserSession.java @@ -8,53 +8,64 @@ import org.springframework.web.context.WebApplicationContext; @Component @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS) public class UserSession { - private Integer userId; - private long mobNo; - private String userType; - private String dispayName; - private String zone; - - public Integer getUserId() { - return userId; - } - - public void setUserId(Integer userId) { - this.userId = userId; - } - - public String getUserType() { - return userType; - } - - public void setUserType(String userType) { - this.userType = userType; - } - - public String getDispayName() { - return dispayName; - } - - public void setDispayName(String dispayName) { - this.dispayName = dispayName; - } - - public long getMobNo() { - return mobNo; + private String USR_NAME; + private String ACNOS; + private String SNO; + private String DESCRIPTION; + private String PERS_CODE; + private String PWD; + private String MOBILENO; + private String USER_LEVEL; + public String getUSR_NAME() { + return USR_NAME; } - - public void setMobNo(long mobNo) { - this.mobNo = mobNo; + public void setUSR_NAME(String uSR_NAME) { + USR_NAME = uSR_NAME; } - - public String getZone() { - return zone; + public String getACNOS() { + return ACNOS; } - - public void setZone(String zone) { - this.zone = zone; + public void setACNOS(String aCNOS) { + ACNOS = aCNOS; + } + public String getSNO() { + return SNO; + } + public void setSNO(String sNO) { + SNO = sNO; } + public String getDESCRIPTION() { + return DESCRIPTION; + } + public void setDESCRIPTION(String dESCRIPTION) { + DESCRIPTION = dESCRIPTION; + } + public String getPERS_CODE() { + return PERS_CODE; + } + public void setPERS_CODE(String pERS_CODE) { + PERS_CODE = pERS_CODE; + } + public String getPWD() { + return PWD; + } + public void setPWD(String pWD) { + PWD = pWD; + } + public String getMOBILENO() { + return MOBILENO; + } + public void setMOBILENO(String mOBILENO) { + MOBILENO = mOBILENO; + } + public String getUSER_LEVEL() { + return USER_LEVEL; + } + public void setUSER_LEVEL(String uSER_LEVEL) { + USER_LEVEL = uSER_LEVEL; + } + - - + } diff --git a/src/main/java/com/election/lokshaba/component/UserSessionInterceptor.java b/src/main/java/com/election/lokshaba/component/UserSessionInterceptor.java index 8547508..3aeb942 100644 --- a/src/main/java/com/election/lokshaba/component/UserSessionInterceptor.java +++ b/src/main/java/com/election/lokshaba/component/UserSessionInterceptor.java @@ -38,7 +38,7 @@ public class UserSessionInterceptor implements HandlerInterceptor { // If logged in, add the userSession to the model // Return true to allow the request to proceed //if (isLoggedIn()) { - if(userSession.getUserId() != null && userSession.getUserType() != null) { + if(userSession.getUSR_NAME() != null && userSession.getPWD() != null) { request.setAttribute("userSession", userSession); } else { request.setAttribute("title", "Login"); @@ -52,6 +52,6 @@ public class UserSessionInterceptor implements HandlerInterceptor { private boolean isLoggedIn() { // Implement your login check logic here // For example, check if the userSession contains the necessary information - return userSession.getUserId() != null && userSession.getUserType() != null; + return userSession.getUSR_NAME() != null && userSession.getPWD() != null; } } diff --git a/src/main/java/com/election/lokshaba/controller/MainController.java b/src/main/java/com/election/lokshaba/controller/MainController.java index b2e2eac..66afa2e 100644 --- a/src/main/java/com/election/lokshaba/controller/MainController.java +++ b/src/main/java/com/election/lokshaba/controller/MainController.java @@ -4,6 +4,7 @@ import com.election.lokshaba.Repository.Userloginrepository; import com.election.lokshaba.component.UserSession; import com.election.lokshaba.model.Userlogin; import com.election.lokshaba.others.AppConfig; +import com.election.lokshaba.service.pollingPersonal.firstOrder.TrainingCenterRepService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -13,10 +14,14 @@ import org.springframework.web.bind.annotation.RequestParam; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; @Controller public class MainController { + @Autowired + TrainingCenterRepService trainingCenterRepService; + @Autowired private UserSession userSession; @@ -45,23 +50,30 @@ public class MainController { // // return "login"; // } - - - - + + + + @PostMapping("/login") - public String login(Model model,@RequestParam String username,@RequestParam String password) { - model.addAttribute("title","ElectionDashboard"); - System.out.println(username +" "+password); - Optional user = userloginrepository.userchecking(username,password); + public String getLogin(@RequestParam("username") String name, + @RequestParam("password") String password){ + System.out.println(name); + System.out.println(password); + List> data = trainingCenterRepService.getLogin(name, password); + if(data!= null) { + userSession.setUSR_NAME(data.get(0).get("USR_NAME")==null?null:data.get(0).get("USR_NAME").toString()); + userSession.setACNOS(data.get(0).get("ACNOS")==null?null:data.get(0).get("ACNOS").toString()); + userSession.setSNO(data.get(0).get("SNO")==null?null:data.get(0).get("SNO").toString()); + userSession.setDESCRIPTION(data.get(0).get("DESCRIPTION")==null?null:data.get(0).get("DESCRIPTION").toString()); + userSession.setPERS_CODE(data.get(0).get("PERS_CODE")==null?null:data.get(0).get("PERS_CODE").toString()); + userSession.setPWD(data.get(0).get("PWD")==null?null:data.get(0).get("PWD").toString()); + userSession.setMOBILENO(data.get(0).get("MOBILENO")==null?null:data.get(0).get("MOBILENO").toString()); + userSession.setUSER_LEVEL(data.get(0).get("MOBILENO")==null?null:data.get(0).get("MOBILENO").toString()); + + return "index"; - if(user.isPresent()) { - userSession.setUserType(user.get().getUsername()); - userSession.setUserId(1); - return "redirect:/index"; } - return "login"; - + return "login"; } diff --git a/src/main/java/com/election/lokshaba/controller/RestAPIController.java b/src/main/java/com/election/lokshaba/controller/RestAPIController.java new file mode 100644 index 0000000..22c3999 --- /dev/null +++ b/src/main/java/com/election/lokshaba/controller/RestAPIController.java @@ -0,0 +1,28 @@ +package com.election.lokshaba.controller; + +import com.election.lokshaba.service.pollingPersonal.firstOrder.PollPersonalTrRepService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/api") +public class RestAPIController { + + @Autowired + private PollPersonalTrRepService pollSer; + + @GetMapping("/acList") + private List> getAttandanceSheetAcList(){ + return pollSer.getAttendanceSheetACListDropdown(); + } + + @GetMapping("/trainingAttHallNo") + private List> getAttendanceSheetHallNo(){ + return pollSer.getAttendanceSheetHallNoListDropdown(); + } +} diff --git a/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/PollPersonalTrRepService.java b/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/PollPersonalTrRepService.java new file mode 100644 index 0000000..86a354b --- /dev/null +++ b/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/PollPersonalTrRepService.java @@ -0,0 +1,62 @@ +package com.election.lokshaba.service.pollingPersonal.firstOrder; + +import com.election.lokshaba.config.DBConnection; +import org.springframework.stereotype.Service; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class PollPersonalTrRepService { + + public List> getAttendanceSheetACListDropdown(){ + String sql = "select * from AC_LIST_NEW WHERE AC_NO!=0 AND DIST_NO=2"; + return getMyList(sql); + } + public List> getAttendanceSheetHallNoListDropdown(){ + String sql = "select distinct hall_no from POLL_PERSON pp WHERE CATEGORY='PO' and c_code='1' and hall_no is not null order by TO_NUMBER(hall_no)"; + return getMyList(sql); + } + + + public List> getMyList(String sql) { + + Connection con = DBConnection.getConnection(); + Statement stmt3; + try { + stmt3 = con.createStatement(); + ResultSet rs3 = stmt3.executeQuery(sql); + + System.out.println("rs = " + rs3); + List> rows = new ArrayList<>(); + while (rs3.next()) { + + Map row = new HashMap<>(); + + ResultSetMetaData metaData = rs3.getMetaData(); + int columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String columnName = metaData.getColumnName(i); + Object columnValue = rs3.getObject(i); + System.out.println(columnName + " :" + columnValue); + row.put(columnName, columnValue); + } + + rows.add(row); + } + return rows; + // return data; + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + + } +} diff --git a/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/TrainingCenterRepService.java b/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/TrainingCenterRepService.java index 69b56f1..f2b41b7 100644 --- a/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/TrainingCenterRepService.java +++ b/src/main/java/com/election/lokshaba/service/pollingPersonal/firstOrder/TrainingCenterRepService.java @@ -1,4 +1,61 @@ package com.election.lokshaba.service.pollingPersonal.firstOrder; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.election.lokshaba.config.DBConnection; + +@Service public class TrainingCenterRepService { + + + public String getLoginQuery(String name, String password) { + String sQry = "select * from ELE_USERMAST where usr_name= '" + name + "' AND pwd= '" + password + "'"; + return sQry; + } + + + public List> getLogin(String name, String password) { + + Connection con = DBConnection.getConnection(); + Statement stmt3; + try { + stmt3 = con.createStatement(); + ResultSet rs3 = stmt3.executeQuery(getLoginQuery(name, password)); + + System.out.println("rs = " + rs3); + List> rows = new ArrayList<>(); + while (rs3.next()) { + + Map row = new HashMap<>(); + + ResultSetMetaData metaData = rs3.getMetaData(); + int columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String columnName = metaData.getColumnName(i); + Object columnValue = rs3.getObject(i); + System.out.println(columnName + " :" + columnValue); + row.put(columnName, columnValue); + } + + rows.add(row); + } + return rows; + // return data; + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + + } } diff --git a/src/main/resources/templates/modules/election/pollingPersonal/firstOrder.html b/src/main/resources/templates/modules/election/pollingPersonal/firstOrder.html index b76c2e0..bf26814 100644 --- a/src/main/resources/templates/modules/election/pollingPersonal/firstOrder.html +++ b/src/main/resources/templates/modules/election/pollingPersonal/firstOrder.html @@ -60,7 +60,7 @@
Polling Personnel Training Reports

    -