diff --git a/build/web/WEB-INF/classes/com/rms/controller/ApplicationController.class b/build/web/WEB-INF/classes/com/rms/controller/ApplicationController.class index e540c46..15d6476 100644 Binary files a/build/web/WEB-INF/classes/com/rms/controller/ApplicationController.class and b/build/web/WEB-INF/classes/com/rms/controller/ApplicationController.class differ diff --git a/build/web/WEB-INF/classes/com/rms/controller/DocumentUploadServlet.class b/build/web/WEB-INF/classes/com/rms/controller/DocumentUploadServlet.class new file mode 100644 index 0000000..1ada60e Binary files /dev/null and b/build/web/WEB-INF/classes/com/rms/controller/DocumentUploadServlet.class differ diff --git a/build/web/WEB-INF/classes/com/rms/controller/JobController.class b/build/web/WEB-INF/classes/com/rms/controller/JobController.class index 754b31e..8c46533 100644 Binary files a/build/web/WEB-INF/classes/com/rms/controller/JobController.class and b/build/web/WEB-INF/classes/com/rms/controller/JobController.class differ diff --git a/build/web/WEB-INF/classes/com/rms/controller/LoginController$Creds.class b/build/web/WEB-INF/classes/com/rms/controller/LoginController$Creds.class deleted file mode 100644 index 43e27b2..0000000 Binary files a/build/web/WEB-INF/classes/com/rms/controller/LoginController$Creds.class and /dev/null differ diff --git a/build/web/WEB-INF/classes/com/rms/controller/LoginController.class b/build/web/WEB-INF/classes/com/rms/controller/LoginController.class index ea675e5..b20daf7 100644 Binary files a/build/web/WEB-INF/classes/com/rms/controller/LoginController.class and b/build/web/WEB-INF/classes/com/rms/controller/LoginController.class differ diff --git a/build/web/WEB-INF/classes/com/rms/controller/SignupController.class b/build/web/WEB-INF/classes/com/rms/controller/SignupController.class index 57d973d..c9fe60b 100644 Binary files a/build/web/WEB-INF/classes/com/rms/controller/SignupController.class and b/build/web/WEB-INF/classes/com/rms/controller/SignupController.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/Application.class b/build/web/WEB-INF/classes/com/rms/model/Application.class index 5c2c001..73367a6 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/Application.class and b/build/web/WEB-INF/classes/com/rms/model/Application.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/AuthService.class b/build/web/WEB-INF/classes/com/rms/model/AuthService.class index a020182..64d5f92 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/AuthService.class and b/build/web/WEB-INF/classes/com/rms/model/AuthService.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/Document.class b/build/web/WEB-INF/classes/com/rms/model/Document.class index 9c3a333..95b6aa0 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/Document.class and b/build/web/WEB-INF/classes/com/rms/model/Document.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/DocumentDAO.class b/build/web/WEB-INF/classes/com/rms/model/DocumentDAO.class new file mode 100644 index 0000000..86f7bcc Binary files /dev/null and b/build/web/WEB-INF/classes/com/rms/model/DocumentDAO.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/JobPosting.class b/build/web/WEB-INF/classes/com/rms/model/JobPosting.class index 12f4f58..f8a461e 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/JobPosting.class and b/build/web/WEB-INF/classes/com/rms/model/JobPosting.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/JobSeeker.class b/build/web/WEB-INF/classes/com/rms/model/JobSeeker.class index e25acca..18abf5d 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/JobSeeker.class and b/build/web/WEB-INF/classes/com/rms/model/JobSeeker.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/JobSeekerService.class b/build/web/WEB-INF/classes/com/rms/model/JobSeekerService.class index 66fd47e..bbe9b0f 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/JobSeekerService.class and b/build/web/WEB-INF/classes/com/rms/model/JobSeekerService.class differ diff --git a/build/web/WEB-INF/classes/com/rms/model/RecruiterService.class b/build/web/WEB-INF/classes/com/rms/model/RecruiterService.class index 2d2c23f..9ee7275 100644 Binary files a/build/web/WEB-INF/classes/com/rms/model/RecruiterService.class and b/build/web/WEB-INF/classes/com/rms/model/RecruiterService.class differ diff --git a/build/web/index.jsp b/build/web/index.jsp index ea05db7..fb49a5e 100644 --- a/build/web/index.jsp +++ b/build/web/index.jsp @@ -1,17 +1,368 @@ -<%-- - Document : index - Created on : Nov 14, 2025, 5:38:19 PM - Author : user ---%> - <%@page contentType="text/html" pageEncoding="UTF-8"%> - JSP Page + + RMS - Recruitment Management System + -

Hello World!

+
+
+
🎯
+

RMS

+

Recruitment Management System

+
+ +
+ Login to Your Account + Create New Account +
+ +
+ QUICK ACCESS +
+ +
+

Development Tools

+ + +
+
+ 1000+ + Active Jobs +
+
+ 5000+ + Candidates +
+
+ 500+ + Companies +
+
+
+
- + \ No newline at end of file diff --git a/build/web/jobseeker_home.jsp b/build/web/jobseeker_home.jsp index d2b8874..1e92c93 100644 --- a/build/web/jobseeker_home.jsp +++ b/build/web/jobseeker_home.jsp @@ -1,158 +1,29 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Document : jobseeker_home + Created on : Nov 17, 2025, 9:26:55 AM + Author : user +--%> +<%@page import="com.rms.model.JobSeeker"%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - Job Seeker Dashboard - RMS - - - - -
- -
-

- 👋 Welcome, ${sessionScope.username != null ? sessionScope.username : 'Job Seeker'}! -

-

- 📅 Today is <%= new java.text.SimpleDateFormat("EEEE, MMMM dd, yyyy").format(new java.util.Date()) %> -

-
- - - - - -
-

📈 Quick Statistics

-
-
-

Total Applications

-

${requestScope.totalApplications != null ? requestScope.totalApplications : 0}

-
- -
-

Pending Applications

-

${requestScope.pendingApplications != null ? requestScope.pendingApplications : 0}

-
- -
-

Accepted Offers

-

${requestScope.acceptedOffers != null ? requestScope.acceptedOffers : 0}

-
-
-
- - -
-

⚡ Quick Actions

-
-
-
👤
-

Update Profile

-

Keep your information current

- Edit Profile -
- -
-
🔍
-

Browse Jobs

-

Find your dream opportunity

- Search Now -
- -
-
📄
-

Upload Documents

-

Add resume and certificates

- Manage Files -
-
-
- - -
- 💡 Tip: Keep your profile updated and check back regularly for new job opportunities! -
-
- - \ No newline at end of file + + + JSP Page + + + <% + JobSeeker recruiter = (JobSeeker)session.getAttribute("user"); + if (recruiter == null) { + response.sendRedirect("login.jsp"); + } + else { + %> +

Hi, <%= recruiter.getUsername() %>!

+ <% + } + %> + + + diff --git a/build/web/post_job.jsp b/build/web/post_job.jsp index d9f7e2c..adf1c4e 100644 --- a/build/web/post_job.jsp +++ b/build/web/post_job.jsp @@ -1,54 +1,57 @@ -<%-- - Document : post_job - Created on : Nov 17, 2025, 9:28:09 AM - Author : user ---%> - <%@page contentType="text/html;charset=UTF-8" language="java" %> - - Post Job - - - - - -

Post a New Job

- -
- -
- - - - - - - - - -
- -
- -← Back to Dashboard - - + + Post Job + + + +

Post a New Job

+ + <% + String error = (String) request.getAttribute("error"); + if (error != null) { + %> +
<%= error %>
+ <% } %> + +
+
+ + + + + + + + + + + + +
+
+ ← Back to Dashboard + \ No newline at end of file diff --git a/build/web/recruiter_home.jsp b/build/web/recruiter_home.jsp index 669d39f..cccfd44 100644 --- a/build/web/recruiter_home.jsp +++ b/build/web/recruiter_home.jsp @@ -1,17 +1,104 @@ <%-- Document : recruiter_home - Created on : Nov 17, 2025, 9:27:50 AM + Created on : Nov 17, 2025, 9:27:50 AM Author : user --%> +<%@page import="com.rms.model.Recruiter"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> - JSP Page + Recruiter Dashboard | RMS + + -

Hello World!

+ <% + Recruiter recruiter = (Recruiter)session.getAttribute("user"); + if (recruiter == null) { + response.sendRedirect("login.jsp"); + } + else { + %> +

Hi, <%= recruiter.getUsername() %>!

+ <% + } + %> diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 6807a2b..81a97c7 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,7 +1,26 @@ - - - - - - - + + + + + + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/controller/LoginController.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/web/login.jsp + file:/C:/Users/mfmma/Downloads/yousef_m_fork/web/register.jsp + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/DBConnect.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/database/rms_testing_complete.sql + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/controller/JobController.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/User.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/Recruiter.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/controller/SearchController.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/controller/SignupController.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/JobSeeker.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/SearchSystemService.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/web/jobseeker_home.jsp + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/JobPosting.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/RecruiterService.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/src/java/com/rms/model/JobSeekerService.java + file:/C:/Users/mfmma/Downloads/yousef_m_fork/web/recruiter_home.jsp + file:/C:/Users/mfmma/Downloads/yousef_m_fork/web/post_job.jsp + + + diff --git a/src/java/com/rms/controller/LoginController.java b/src/java/com/rms/controller/LoginController.java index a1e2ad8..32c96be 100644 --- a/src/java/com/rms/controller/LoginController.java +++ b/src/java/com/rms/controller/LoginController.java @@ -1,220 +1,188 @@ package com.rms.controller; -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template - */ - +import com.rms.model.AuthService; import com.rms.model.DBConnect; import com.rms.model.JobSeeker; import com.rms.model.Recruiter; -import java.io.IOException; -import java.io.PrintWriter; + import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.*; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.annotation.MultipartConfig; -/** - * - * @author user - */ -@MultipartConfig +import java.sql.*; + @WebServlet(urlPatterns = {"/LoginController"}) +@MultipartConfig public class LoginController extends HttpServlet { - /** - * Processes requests for both HTTP GET and POST - * methods. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - - public static class Creds { - public String email; - public String password; - }; - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - response.setContentType("text/html;charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - - } finally { - out.close(); + // ------------------------------------------------------------------- + // Utility: SHA-256 hashing + // ------------------------------------------------------------------- + + + + // ------------------------------------------------------------------- + // Query: Validate user credentials + // ------------------------------------------------------------------- + private ResultSet fetchUser(Connection conn, String email, String hashedPassword) throws SQLException { + + String sql = "SELECT * FROM user WHERE email = ? AND password = ?"; + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, email); + stmt.setString(2, hashedPassword); + return stmt.executeQuery(); + } + + + // ------------------------------------------------------------------- + // Query: Fetch Job Seeker details + // ------------------------------------------------------------------- + private JobSeeker loadJobSeeker(Connection conn, String userId, String username, String email, String role) + throws SQLException { + + String sql = "SELECT * FROM `job seeker` WHERE jobseeker_id = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, userId); + try (ResultSet rs = stmt.executeQuery()) { + if (!rs.next()) return null; + + String specialization = rs.getString("specialization"); + String fullName = rs.getString("full_name"); + int experienceYears = Integer.parseInt(rs.getString("experience_years")); + String skills = rs.getString("skills"); + String interests = rs.getString("interests"); + String intro = rs.getString("User_Introduction"); + + byte[] resume = loadUserResume(conn, userId); + + return new JobSeeker( + username, + Integer.parseInt(userId), + email, + role, + specialization, + fullName, + experienceYears, + skills, + interests, + intro, + resume + ); + } } } - // - /** - * Handles the HTTP GET method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); + + // ------------------------------------------------------------------- + // Query: Fetch Recruiter details + // ------------------------------------------------------------------- + private Recruiter loadRecruiter(Connection conn, String userId, String username, String email) + throws SQLException { + + String sql = "SELECT * FROM recruiter WHERE recruiter_id = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, userId); + + try (ResultSet rs = stmt.executeQuery()) { + if (!rs.next()) return null; + + String companyId = rs.getString("company_id"); + String companyName = rs.getString("company_name"); + + return new Recruiter( + Integer.parseInt(userId), + username, + email, + companyId, + companyName + ); + } + } } - /** - * Handles the HTTP POST method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - - private static String bytesToHex(byte[] hash) { - StringBuilder hexString = new StringBuilder(2 * hash.length); - for (int i = 0; i < hash.length; i++) { - String hex = Integer.toHexString(0xff & hash[i]); - if(hex.length() == 1) { - hexString.append('0'); + + // ------------------------------------------------------------------- + // Query: Load Resume Document + // ------------------------------------------------------------------- + private byte[] loadUserResume(Connection conn, String userId) throws SQLException { + + String sql = + "SELECT filedata FROM document WHERE jobseeker_id = ? LIMIT 1"; + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, userId); + + try (ResultSet rs = stmt.executeQuery()) { + return rs.next() ? rs.getBytes("filedata") : null; + } } - hexString.append(hex); } - return hexString.toString(); -} - + + + // ------------------------------------------------------------------- + // HTTP: POST (Login) + // ------------------------------------------------------------------- + @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - -// processRequest(request, response); - - String email = request.getParameter("email"); - String password = request.getParameter("password"); - - - - - String db_user = "admin"; - String db_password = "ManarNoorYousefRawan"; - - try { - try { - Class.forName("com.mysql.cj.jdbc.Driver"); // optional - Connection conn = DBConnect.getConnection(); - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] encodedhash = digest.digest( - password.getBytes(StandardCharsets.UTF_8)); - System.out.println(password); - System.out.println(bytesToHex(encodedhash)); - Statement statement =conn.createStatement(); - String query = "SELECT * FROM user WHERE password= ? AND email = ?"; - PreparedStatement stmt = conn.prepareStatement(query); - stmt.setString(1, bytesToHex(encodedhash)); - stmt.setString(2, email); - ResultSet result = stmt.executeQuery(); - System.out.println("Fetching Data"); - if (!result.next()) { - response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid Credienitals"); - } - else { - do { - String role = result.getString("role"); - String user_id = result.getString("user_id"); - String username = result.getString("username"); - if (role.equals("jobseeker")) { - String queryJobSeeker = "SELECT * FROM `job seeker` WHERE jobseeker_id=?"; - - PreparedStatement stmt1 = conn.prepareStatement(queryJobSeeker); - stmt1.setString(1, user_id); - ResultSet result1 = stmt1.executeQuery(); - System.out.println("Running here!"); - while (result1.next()) { - String specialization = result1.getString("specialization"); - String full_name = result1.getString("full_name"); - String experience_years = result1.getString("experience_years"); - String interests = result1.getString("interests"); - String skills = result1.getString("skills"); - String user_introduction = result1.getString("User_Introduction"); - String queryDocument = - "SELECT d.fileData " + - "FROM document d " + - "JOIN `job seeker` js ON js.jobseeker_id = d.jobseeker_id " + - "WHERE d.jobseeker_id = ?"; - -PreparedStatement stmt2 = conn.prepareStatement(queryDocument); -stmt2.setString(1, user_id); -ResultSet result3 = stmt2.executeQuery(); - System.out.println("Got Job Details"); - while (result3.next()) { - byte[] fileData= result3.getBytes("fileData"); - int userid = Integer.parseInt(user_id); - int years = Integer.parseInt(experience_years); - JobSeeker job_seeker = new JobSeeker(username, userid, email, role, specialization, full_name, years, skills, interests, user_introduction, fileData); - request.getSession().setAttribute("user", job_seeker); - System.out.println("Got Document"); - response.sendRedirect("jobseeker_home.jsp"); - - - } - - } - - } - else { - String queryRecruiter = "SELECT * FROM recruiter WHERE recruiter_id=?"; - PreparedStatement stmt1 = conn.prepareStatement(queryRecruiter); - stmt1.setString(1, user_id); - ResultSet result1 = stmt1.executeQuery(); - System.out.println("Running here!"); - while (result1.next()) { - String company_id = result1.getString("company_id"); - String company_name = result1.getString("company_name"); - Recruiter recruiter = new Recruiter(Integer.parseInt(user_id), username, email, company_id, company_name); - request.getSession().setAttribute("user", recruiter); - response.sendRedirect("recruiter_home.jsp"); - - - } - } - - - } while (result.next()); - } - - } catch (ClassNotFoundException ex) { - Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex); + throws IOException, ServletException { + + String email = request.getParameter("email"); + String password = request.getParameter("password"); + + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (Exception ignored) {} + + try (Connection conn = DBConnect.getConnection()) { + + // Hash password + AuthService auth = new AuthService(); + String hashedPassword = auth.hashPassword(password); + + // Validate user + ResultSet rs = fetchUser(conn, email, hashedPassword); + if (!rs.next()) { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid email or password"); + return; + } + + // Extract common fields + String userId = rs.getString("user_id"); + String username = rs.getString("username"); + String role = rs.getString("role"); + + HttpSession session = request.getSession(); + + // Load role-specific data + if ("jobseeker".equals(role)) { + JobSeeker jobSeeker = loadJobSeeker(conn, userId, username, email, role); + if (jobSeeker == null) { + response.sendError(500, "JobSeeker profile missing"); + return; } - - - } catch (SQLException | NoSuchAlgorithmException ex) { - Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex); - } - System.out.println("Connected successfully!"); - - } - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ - @Override - public String getServletInfo() { - return "Short description"; - }// + session.setAttribute("user", jobSeeker); + response.sendRedirect("jobseeker_home.jsp"); + } -} + else if ("recruiter".equals(role)) { + Recruiter recruiter = loadRecruiter(conn, userId, username, email); + if (recruiter == null) { + response.sendError(500, "Recruiter profile missing"); + return; + } + + session.setAttribute("user", recruiter); + response.sendRedirect("recruiter_home.jsp"); + } + } catch (SQLException | NoSuchAlgorithmException e) { + e.printStackTrace(); + response.sendError(500, "Server Error: " + e.getMessage()); + } + } +} diff --git a/src/java/com/rms/controller/SignupController.java b/src/java/com/rms/controller/SignupController.java index 45c2fda..a8a102d 100644 --- a/src/java/com/rms/controller/SignupController.java +++ b/src/java/com/rms/controller/SignupController.java @@ -5,6 +5,7 @@ * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template */ +import com.rms.model.AuthService; import com.rms.model.DBConnect; import com.rms.model.JobSeeker; import com.rms.model.Recruiter; @@ -75,41 +76,12 @@ private byte[] readUploadedFile(Part filePart) throws IOException { // ------------------------------------------------------------------- // DB Utility: Get user_id after insert // ------------------------------------------------------------------- - private String getUserId(Connection conn, String email, String hashedPassword) throws SQLException { - String sql = "SELECT user_id FROM user WHERE email = ? AND password = ?"; - try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, email); - stmt.setString(2, hashedPassword); - ResultSet rs = stmt.executeQuery(); - if (rs.next()) return rs.getString("user_id"); - } - return null; - } + // ------------------------------------------------------------------- // Insert: Generic user // ------------------------------------------------------------------- - private User insertUser(Connection conn, String username, String email, String hashedPassword, String role, HttpServletResponse response) - throws SQLException, IOException { - - String sql = "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, ?)"; - try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, username); - stmt.setString(2, email); - stmt.setString(3, hashedPassword); - stmt.setString(4, role); - int num = stmt.executeUpdate(); - if (num == 0) { - response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username/email already used"); - } - } - catch (Exception e) { - response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username/email already used"); - - } - String id = getUserId(conn, email, hashedPassword); - return new User(Integer.parseInt(id), username, email, role); - } + // ------------------------------------------------------------------- // Insert: Recruiter @@ -207,10 +179,10 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) try (Connection conn = DBConnect.getConnection()) { String hashedPassword = hashPassword(password); + AuthService auth = new AuthService(); + User user = auth.insertUser(conn, username, email, hashedPassword, role, response); - User user = insertUser(conn, username, email, hashedPassword, role, response); - - String userId = getUserId(conn, email, hashedPassword); + String userId = auth.getUserId(conn, email, hashedPassword); if (userId == null) { System.err.println("Error: User ID not found."); return; @@ -219,7 +191,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) if ("recruiter".equals(role)) { Recruiter recruiter = insertRecruiter(conn, user, request); request.getSession().setAttribute("user", recruiter); - response.sendRedirect("recruiter_home.jsp"); + response.sendRedirect("recruiter_home.jsp"); } else { if (pdfBytes != null) { JobSeeker jobSeeker= insertJobSeeker(conn, user, pdfBytes, request); diff --git a/src/java/com/rms/model/AuthService.java b/src/java/com/rms/model/AuthService.java index 68a4006..4018b28 100644 --- a/src/java/com/rms/model/AuthService.java +++ b/src/java/com/rms/model/AuthService.java @@ -1,199 +1,185 @@ -//package com.rms.model; -// -//import java.sql.Connection; -//import java.sql.PreparedStatement; -//import java.sql.ResultSet; -//import java.sql.SQLException; -//import java.nio.charset.StandardCharsets; -//import java.security.MessageDigest; -//import java.security.NoSuchAlgorithmException; -//import java.util.logging.Level; -//import java.util.logging.Logger; -// -//public class AuthService { -// -// private static final Logger LOGGER = Logger.getLogger(AuthService.class.getName()); -// -// /** -// * Converts byte array to hexadecimal string (for password hashing). -// */ -// private static String bytesToHex(byte[] hash) { -// StringBuilder hexString = new StringBuilder(2 * hash.length); -// for (int i = 0; i < hash.length; i++) { -// String hex = Integer.toHexString(0xff & hash[i]); -// if (hex.length() == 1) { -// hexString.append('0'); -// } -// hexString.append(hex); -// } -// return hexString.toString(); -// } -// -// /** -// * Authenticates user and returns User object with role, or null if login -// * fails. -// * -// * @param email User's email address -// * @param rawPassword Plain text password from login form -// * @return User object if authentication succeeds, null otherwise -// */ -// public User authenticateUser(String email, String rawPassword) { -// Connection conn = null; -// PreparedStatement stmt = null; -// ResultSet result = null; -// User user = null; -// -// try { -// // HASH THE INPUT PASSWORD using SHA-256 -// MessageDigest digest = MessageDigest.getInstance("SHA-256"); -// byte[] encodedhash = digest.digest(rawPassword.getBytes(StandardCharsets.UTF_8)); -// String hashedPassword = bytesToHex(encodedhash); -// -// // DEBUG: Print to console for troubleshooting -// System.out.println("=== LOGIN DEBUG ==="); -// System.out.println("Input Email: " + email); -// System.out.println("Input Password (raw): " + rawPassword); -// System.out.println("Hashed Password: " + hashedPassword); -// -// // Get database connection -// conn = DBConnect.getConnection(); -// -// if (conn == null) { -// System.out.println("ERROR: Database connection is NULL!"); -// return null; -// } -// -// System.out.println("Database connection successful"); -// -// // Query to find user by email and password -// String query = "SELECT user_id, username, email, password, role FROM User WHERE email = ?"; -// stmt = conn.prepareStatement(query); -// stmt.setString(1, email.trim()); -// -// result = stmt.executeQuery(); -// -// if (result.next()) { -// // User found, now check password -// String storedPassword = result.getString("password"); -// -// System.out.println("User found in database"); -// System.out.println("Stored Password: " + storedPassword); -// System.out.println("Passwords Match: " + hashedPassword.equals(storedPassword)); -// -// // Compare hashed passwords -// if (hashedPassword.equals(storedPassword)) { -// // Password matches - create User object -// user = new User(); -// user.setUser_id(result.getInt("user_id")); -// user.setUsername(result.getString("username")); -// user.setEmail(result.getString("email")); -// user.setRole(result.getString("role")); -// -// System.out.println("✅ Login SUCCESS for user: " + user.getUsername() + " (Role: " + user.getRole() + ")"); -// LOGGER.log(Level.INFO, "User logged in successfully: {0}", user.getUsername()); -// } else { -// System.out.println("❌ Password mismatch!"); -// LOGGER.log(Level.WARNING, "Failed login attempt for email: {0} (wrong password)", email); -// } -// } else { -// System.out.println("❌ No user found with email: " + email); -// LOGGER.log(Level.WARNING, "Failed login attempt - email not found: {0}", email); -// } -// -// } catch (SQLException ex) { -// System.out.println("❌ SQL ERROR: " + ex.getMessage()); -// LOGGER.log(Level.SEVERE, "Database error during authentication", ex); -// ex.printStackTrace(); -// } catch (NoSuchAlgorithmException ex) { -// System.out.println("❌ HASHING ERROR: " + ex.getMessage()); -// LOGGER.log(Level.SEVERE, "Password hashing algorithm not found", ex); -// ex.printStackTrace(); -// } finally { -// // Close all database resources -// try { -// if (result != null) { -// result.close(); -// } -// } catch (SQLException e) { -// LOGGER.log(Level.WARNING, "Error closing ResultSet", e); -// } -// try { -// if (stmt != null) { -// stmt.close(); -// } -// } catch (SQLException e) { -// LOGGER.log(Level.WARNING, "Error closing PreparedStatement", e); -// } -// try { -// if (conn != null) { -// conn.close(); -// } -// } catch (SQLException e) { -// LOGGER.log(Level.WARNING, "Error closing Connection", e); -// } -// } -// -// System.out.println("==================="); -// return user; -// } -// -// /** -// * Registers a new user in the system. -// * -// * @param user User object containing registration details -// * @return true if registration succeeds, false otherwise -// */ -// public boolean registerUser(User user) { -// Connection conn = null; -// PreparedStatement stmt = null; -// boolean success = false; -// -// try { -// // Hash the password before storing -// MessageDigest digest = MessageDigest.getInstance("SHA-256"); -// byte[] encodedhash = digest.digest(user.getPassword().getBytes(StandardCharsets.UTF_8)); -// String hashedPassword = bytesToHex(encodedhash); -// -// conn = DBConnect.getConnection(); -// -// String query = "INSERT INTO User (username, email, password, role) VALUES (?, ?, ?, ?)"; -// stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); -// -// stmt.setString(1, user.getUsername()); -// stmt.setString(2, user.getEmail()); -// stmt.setString(3, hashedPassword); -// stmt.setString(4, user.getRole()); -// -// int rowsAffected = stmt.executeUpdate(); -// success = (rowsAffected > 0); -// -// if (success) { -// // Get the generated user_id -// ResultSet generatedKeys = stmt.getGeneratedKeys(); -// if (generatedKeys.next()) { -// user.setUser_id(generatedKeys.getInt(1)); -// } -// LOGGER.log(Level.INFO, "User registered successfully: {0}", user.getUsername()); -// } -// -// } catch (SQLException | NoSuchAlgorithmException ex) { -// LOGGER.log(Level.SEVERE, "Error during user registration", ex); -// ex.printStackTrace(); -// } finally { -// try { -// if (stmt != null) { -// stmt.close(); -// } -// } catch (SQLException e) { -// } -// try { -// if (conn != null) { -// conn.close(); -// } -// } catch (SQLException e) { -// } -// } -// -// return success; -// } -//} +package com.rms.model; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.http.HttpServletResponse; + +public class AuthService { + + private static final Logger LOGGER = Logger.getLogger(AuthService.class.getName()); + public String getUserId(Connection conn, String email, String hashedPassword) throws SQLException { + String sql = "SELECT user_id FROM user WHERE email = ? AND password = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, email); + stmt.setString(2, hashedPassword); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) return rs.getString("user_id"); + } + return null; + } + public String hashPassword(String password) throws NoSuchAlgorithmException { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] encoded = digest.digest(password.getBytes(StandardCharsets.UTF_8)); + + StringBuilder hexString = new StringBuilder(); + for (byte b : encoded) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } + /** + * Converts byte array to hexadecimal string (for password hashing). + */ + private static String bytesToHex(byte[] hash) { + StringBuilder hexString = new StringBuilder(2 * hash.length); + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } + + /** + * Authenticates user and returns User object with role, or null if login + * fails. + * + * @param email User's email address + * @param rawPassword Plain text password from login form + * @return User object if authentication succeeds, null otherwise + */ + public User authenticateUser(String email, String rawPassword) { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet result = null; + User user = null; + + try { + // HASH THE INPUT PASSWORD using SHA-256 + + String hashedPassword = hashPassword(rawPassword); + + // DEBUG: Print to console for troubleshooting + System.out.println("=== LOGIN DEBUG ==="); + System.out.println("Input Email: " + email); + System.out.println("Input Password (raw): " + rawPassword); + System.out.println("Hashed Password: " + hashedPassword); + + // Get database connection + conn = DBConnect.getConnection(); + + if (conn == null) { + System.out.println("ERROR: Database connection is NULL!"); + return null; + } + + System.out.println("Database connection successful"); + + // Query to find user by email and password + String query = "SELECT user_id, username, email, password, role FROM User WHERE email = ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, email.trim()); + + result = stmt.executeQuery(); + + if (result.next()) { + // User found, now check password + String storedPassword = result.getString("password"); + + System.out.println("User found in database"); + System.out.println("Stored Password: " + storedPassword); + System.out.println("Passwords Match: " + hashedPassword.equals(storedPassword)); + + // Compare hashed passwords + if (hashedPassword.equals(storedPassword)) { + // Password matches - create User object + user = new User(); + user.setUser_id(result.getInt("user_id")); + user.setUsername(result.getString("username")); + user.setEmail(result.getString("email")); + user.setRole(result.getString("role")); + + System.out.println("✅ Login SUCCESS for user: " + user.getUsername() + " (Role: " + user.getRole() + ")"); + LOGGER.log(Level.INFO, "User logged in successfully: {0}", user.getUsername()); + } else { + System.out.println("❌ Password mismatch!"); + LOGGER.log(Level.WARNING, "Failed login attempt for email: {0} (wrong password)", email); + } + } else { + System.out.println("❌ No user found with email: " + email); + LOGGER.log(Level.WARNING, "Failed login attempt - email not found: {0}", email); + } + + } catch (SQLException ex) { + System.out.println("❌ SQL ERROR: " + ex.getMessage()); + LOGGER.log(Level.SEVERE, "Database error during authentication", ex); + ex.printStackTrace(); + } catch (NoSuchAlgorithmException ex) { + System.out.println("❌ HASHING ERROR: " + ex.getMessage()); + LOGGER.log(Level.SEVERE, "Password hashing algorithm not found", ex); + ex.printStackTrace(); + } finally { + // Close all database resources + try { + if (result != null) { + result.close(); + } + } catch (SQLException e) { + LOGGER.log(Level.WARNING, "Error closing ResultSet", e); + } + try { + if (stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + LOGGER.log(Level.WARNING, "Error closing PreparedStatement", e); + } + try { + if (conn != null) { + conn.close(); + } + } catch (SQLException e) { + LOGGER.log(Level.WARNING, "Error closing Connection", e); + } + } + + System.out.println("==================="); + return user; + } + + + + public User insertUser(Connection conn, String username, String email, String hashedPassword, String role, HttpServletResponse response) + throws SQLException, IOException { + + String sql = "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, ?)"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, username); + stmt.setString(2, email); + stmt.setString(3, hashedPassword); + stmt.setString(4, role); + int num = stmt.executeUpdate(); + if (num == 0) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username/email already used"); + } + } + catch (Exception e) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username/email already used"); + + } + String id = getUserId(conn, email, hashedPassword); + return new User(Integer.parseInt(id), username, email, role); + } +} diff --git a/web/jobseeker_home.jsp b/web/jobseeker_home.jsp index d2b8874..1e92c93 100644 --- a/web/jobseeker_home.jsp +++ b/web/jobseeker_home.jsp @@ -1,158 +1,29 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Document : jobseeker_home + Created on : Nov 17, 2025, 9:26:55 AM + Author : user +--%> +<%@page import="com.rms.model.JobSeeker"%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - Job Seeker Dashboard - RMS - - - - -
- -
-

- 👋 Welcome, ${sessionScope.username != null ? sessionScope.username : 'Job Seeker'}! -

-

- 📅 Today is <%= new java.text.SimpleDateFormat("EEEE, MMMM dd, yyyy").format(new java.util.Date()) %> -

-
- - - - - -
-

📈 Quick Statistics

-
-
-

Total Applications

-

${requestScope.totalApplications != null ? requestScope.totalApplications : 0}

-
- -
-

Pending Applications

-

${requestScope.pendingApplications != null ? requestScope.pendingApplications : 0}

-
- -
-

Accepted Offers

-

${requestScope.acceptedOffers != null ? requestScope.acceptedOffers : 0}

-
-
-
- - -
-

⚡ Quick Actions

-
-
-
👤
-

Update Profile

-

Keep your information current

- Edit Profile -
- -
-
🔍
-

Browse Jobs

-

Find your dream opportunity

- Search Now -
- -
-
📄
-

Upload Documents

-

Add resume and certificates

- Manage Files -
-
-
- - -
- 💡 Tip: Keep your profile updated and check back regularly for new job opportunities! -
-
- - \ No newline at end of file + + + JSP Page + + + <% + JobSeeker recruiter = (JobSeeker)session.getAttribute("user"); + if (recruiter == null) { + response.sendRedirect("login.jsp"); + } + else { + %> +

Hi, <%= recruiter.getUsername() %>!

+ <% + } + %> + + + diff --git a/web/recruiter_home.jsp b/web/recruiter_home.jsp index 8823716..cccfd44 100644 --- a/web/recruiter_home.jsp +++ b/web/recruiter_home.jsp @@ -3,11 +3,9 @@ Created on : Nov 17, 2025, 9:27:50 AM Author : user --%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ page import="java.util.List" %> -<%@ page import="com.rms.model.JobPosting" %> -<%@ page import="com.rms.model.User" %> - +<%@page import="com.rms.model.Recruiter"%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> @@ -91,73 +89,16 @@ -
- <% - // Optional: Get user info from session for personalized welcome - User user = (User) session.getAttribute("user"); - String username = (user != null) ? user.getUsername() : "Recruiter"; - %> - -

Welcome, <%= username%> | Recruiter Dashboard

- - - -
- -

Your Active Job Listings

- - <% - // Retrieve the list of JobPosting objects set by JobController.doGet - List jobList = (List) request.getAttribute("jobList"); - Integer jobCount = (Integer) request.getAttribute("jobCount"); - - if (jobList != null && !jobList.isEmpty()) { - %> -

Total Active Jobs: <%= jobCount%>

- - - - - - - - - - - - - - - <% - for (JobPosting job : jobList) { - %> - - - - - - - - - - <% - } - %> - -
IDJob TitleLocationSalaryStatusDate PostedActions
<%= job.getId()%><%= job.getTitle()%><%= job.getLocation()%>$<%= String.format("%.2f", job.getSalary())%>;"><%= job.getStatus()%><%= job.getDatePosted()%> - Edit | - View Applicants -
- <% } else { %> -

You currently have no active job listings. Click "Post New Job" above to begin hiring.

- <% }%> - -
+ <% + Recruiter recruiter = (Recruiter)session.getAttribute("user"); + if (recruiter == null) { + response.sendRedirect("login.jsp"); + } + else { + %> +

Hi, <%= recruiter.getUsername() %>!

+ <% + } + %> - \ No newline at end of file +