0% found this document useful (0 votes)
4 views15 pages

GrNo.2 Registration Module

The document contains a web application for an Import Export System, featuring registration and login functionalities with user roles (consumer and seller). It includes frontend HTML/CSS for user interfaces, middleware Java classes for database connections and user registration/login operations, and backend SQL scripts for database schema creation. The application utilizes Bootstrap for styling and employs a MySQL database to manage user data and product orders.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

GrNo.2 Registration Module

The document contains a web application for an Import Export System, featuring registration and login functionalities with user roles (consumer and seller). It includes frontend HTML/CSS for user interfaces, middleware Java classes for database connections and user registration/login operations, and backend SQL scripts for database schema creation. The application utilizes Bootstrap for styling and employs a MySQL database to manage user data and product orders.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Frontend:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Import Export System</title>
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<style>
body {
background-color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.register-card {
background: rgba(255, 255, 255, 0.7); /* Transparent white */
backdrop-filter: blur(10px); /* Glassmorphism effect */
padding: 30px;
border-radius: 15px; /* Rounded corners */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-width: 400px;
width: 100%;
text-align: center;
}
.form-control {
border-radius: 10px; /* Rounded input fields */
}
.btn-register {
background: linear-gradient(to right, #ff6f61, #ff9052); /* Soft red-
orange */
color: white;
font-weight: bold;
border-radius: 25px;
padding: 8px 20px;
transition: 0.3s ease-in-out;
border: none;
}
.btn-register:hover {
background: linear-gradient(to right, #ff9052, #ff6f61); /* Reverse
gradient */
color: white;
transform: scale(1.05);
}
.bottom-text a {
text-decoration: none;
font-weight: bold;
color: blue;
transition: 0.3s ease-in-out;
}
.bottom-text a:hover {
color: darkblue;
}
</style>
</head>
<body>

<div class="register-card">
<h3 class="text-center">Register</h3>
<form action="registerController" method="post">
<div class="mb-3">
<label for="port_id" class="form-label">Port ID</label>
<input type="text" class="form-control" name="port_id"
placeholder="Enter your Port ID" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" name="password"
placeholder="Enter your Password" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm
Password</label>
<input type="password" class="form-control" name="confirm_password"
placeholder="Confirm your Password" required>
</div>
<div class="mb-3">
<label for="location" class="form-label">Location</label>
<input type="text" class="form-control" name="location"
placeholder="Enter your Location" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" name="role" required>
<option selected disabled>Select Role</option>
<option value="consumer">Consumer</option>
<option value="seller">Seller</option>
</select>
</div>
<div class="d-flex justify-content-center mt-4">
<button type="submit" class="btn btn-register" value="register"
name="register">Register</button>
</div>
</form>

<!-- Already have an account? -->


<div class="bottom-text text-center m-3">
<p>Already have an account? <a href="login.jsp">Login</a></p>
<p><a href="index.jsp">⬅ Back to Home</a></p> <!-- Added Back to Home
Link -->
</div>
</div>

<!-- Bootstrap JS -->


<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-


8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - Import Export System</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<style>
body {
background-color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-card {
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
padding: 30px;
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-width: 400px;
width: 100%;
}
.profile-img {
width: 80px;
height: 80px;
border-radius: 50%;
margin-bottom: 15px;
}
.form-control {
border-radius: 10px;
}
.btn-login {
background: linear-gradient(to right, #ff6f61, #ff9052);
color: white;
font-weight: bold;
border-radius: 25px;
padding: 8px 20px;
transition: 0.3s ease-in-out;
border: none;
}
.btn-login:hover {
background: linear-gradient(to right, #ff9052, #ff6f61);
color: white;
transform: scale(1.05);
}
.bottom-text a {
text-decoration: none;
font-weight: bold;
color: blue;
transition: 0.3s ease-in-out;
}
.bottom-text a:hover {
color: darkblue;
}
</style>
</head>
<body>

<div class="login-card">
<div class="d-flex justify-content-center">
<img src="https://cdn-icons-png.flaticon.com/512/3135/3135715.png"
alt="Profile" class="profile-img">
</div>
<h3 class="text-center">Login</h3>

<%-- Display error message if login fails --%>


<% String errorMessage = (String) request.getAttribute("errorMessage");
if (errorMessage != null) { %>
<div class="alert alert-danger text-center"><%= errorMessage %></div>
<% } %>

<form action="LoginController" method="post">


<div class="mb-3">
<label for="port_id" class="form-label">Port ID</label>
<input type="text" class="form-control" id="port_id" name="port_id"
placeholder="Enter your Port ID" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password"
name="password" placeholder="Enter your Password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option selected disabled>Select Role</option>
<option value="consumer">Consumer</option>
<option value="seller">Seller</option>
</select>
</div>
<div class="d-flex justify-content-center mt-4">
<button type="submit" class="btn btn-success
btn-login">Login</button>
</div>
</form>

<div class="bottom-text text-center m-3">


<p>New here? <a href="register.jsp">Create an account</a></p>
<p><a href="index.jsp">⬅ Back to Home</a></p> <!-- Added Back to Home
Link -->
</div>
</div>

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-


8" %>
<%
session.invalidate(); // Destroy session
response.sendRedirect("login.jsp"); // Redirect to login page
%>

Middleware:

package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class GetConnection {

public static Connection getConnection() {


Connection connection = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection =
DriverManager.getConnection("jdbc:mysql://localhost:3307/db_1", "root", "pass");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return connection;
}
}

package model;

import operationImplementor.RegisterImplementor;

public class Register_Pojo {

private int port_id;


private String password;
private String confirm_password;
private String location;
private String role;

public int getPort_id() {


return port_id;
}

public void setPort_id(int port_id) {


this.port_id = port_id;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


this.password = password;
}

public String getConfirm_password() {


return confirm_password;
}

public void setConfirm_password(String confirm_password) {


this.confirm_password = confirm_password;
}

public String getLocation() {


return location;
}

public void setLocation(String location) {


this.location = location;
}

public String getRole() {


return role;
}

public void setRole(String role) {


this.role = role;
}

public void register_user(Register_Pojo pojo) {


new RegisterImplementor().registerUser(pojo);
}
}

package operations;

import model.Register_Pojo;

public interface Operations {

public void registerUser(Register_Pojo pojo);

package operationImplementor;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import db.GetConnection;
import model.Register_Pojo;
import operations.Operations;

public class RegisterImplementor implements Operations {

public void registerUser(Register_Pojo pojo) {


Connection conn = null;
CallableStatement cs = null;

try {
conn = GetConnection.getConnection();
cs = conn.prepareCall("CALL register_user(?,?,?,?,?)");

cs.setInt(1, pojo.getPort_id());
cs.setString(2, pojo.getPassword());
cs.setString(3, pojo.getConfirm_password());
cs.setString(4, pojo.getLocation());
cs.setString(5, pojo.getRole());
boolean hasResults = cs.execute(); // Executes the procedure

if (!hasResults) {
System.out.println("Registration successful");
} else {
System.out.println("Registration failed");
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (cs != null) cs.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public String loginUser(int portId, String password, String role) {


Connection conn = null;
CallableStatement stmt = null;
ResultSet rs = null;
String loginMessage = "Invalid credentials"; // Default message

try {
conn = GetConnection.getConnection();
stmt = conn.prepareCall("{CALL login_user(?, ?, ?)}");

stmt.setInt(1, portId);
stmt.setString(2, password); // Assuming password is stored as hashed
in DB
stmt.setString(3, role);

rs = stmt.executeQuery();

if (rs.next()) {
loginMessage = rs.getString(1); // Should return 'Login successful'
or 'Invalid credentials'
System.out.println("Login result from DB: " + loginMessage); //
Debugging
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return loginMessage; // Return success or failure message
}
}
package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Register_Pojo;

@WebServlet("/registerController")
public class registerController extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

Register_Pojo pojo = new Register_Pojo();


String action = request.getParameter("register");

try {
pojo.setPort_id(Integer.parseInt(request.getParameter("port_id")));
pojo.setPassword(request.getParameter("password"));
pojo.setConfirm_password(request.getParameter("confirm_password"));
pojo.setLocation(request.getParameter("location"));
pojo.setRole(request.getParameter("role"));

if ("register".equals(action)) {
pojo.register_user(pojo);
System.out.println("User registered successfully!");
response.sendRedirect("login.jsp"); // Redirect to success page
} else {
System.out.println("Error in registration: invalid action.");
response.sendRedirect("register.jsp"); // Redirect to error page
}

} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("register.jsp");
}
}
}

Backend:

create database db_1;

use db_1;

-- Nehal Start
CREATE TABLE consumer_port (
port_id INT PRIMARY KEY AUTO_INCREMENT,
password VARCHAR(255) NOT NULL,
location VARCHAR(255),
role VARCHAR(255) NOT NULL
);

desc
use

desc consumer_port;

CREATE TABLE seller_port (


port_id INT PRIMARY KEY AUTO_INCREMENT,
password VARCHAR(255) NOT NULL,
location VARCHAR(255),
role VARCHAR(255) NOT NULL
);

select * from consumer_port;


desc seller_port;

CREATE TABLE products (


product_id INT PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(255) NOT NULL,
quantity INT NOT NULL,
price FLOAT NOT NULL CHECK (price >= 0),
seller_id INT,
FOREIGN KEY (seller_id) REFERENCES seller_port(port_id) ON DELETE CASCADE
);

desc products;

CREATE TABLE orders (


order_id INT PRIMARY KEY AUTO_INCREMENT,
product_id INT,
consumer_port_id INT,
quantity INT NOT NULL CHECK (quantity > 0),
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
order_placed BOOLEAN DEFAULT FALSE,
shipped BOOLEAN DEFAULT FALSE,
out_for_delivery BOOLEAN DEFAULT FALSE,
delivered BOOLEAN DEFAULT FALSE,
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE,
FOREIGN KEY (consumer_port_id) REFERENCES consumer_port(port_id) ON DELETE
CASCADE
);
desc consumer_port;

desc

CREATE TABLE reported_products (


report_id INT PRIMARY KEY AUTO_INCREMENT,
consumer_port_id INT,
product_id INT,
issue_type VARCHAR(255) NOT NULL,
solution ENUM('solved', 'pending') DEFAULT 'pending',
report_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (consumer_port_id) REFERENCES consumer_port(port_id) ON DELETE
CASCADE,
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE
);
desc reported_products;

drop table reported_products;

CREATE TABLE reported_products (


report_id INT PRIMARY KEY AUTO_INCREMENT,
consumer_port_id INT NOT NULL,
product_id INT NOT NULL,
issue_type VARCHAR(255) NOT NULL,
solution ENUM('solved', 'pending') DEFAULT 'pending',
report_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (consumer_port_id) REFERENCES consumer_port(port_id) ON DELETE
CASCADE,
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE
);

-- Backup table for consumer_port


CREATE TABLE consumer_port_backup (
port_id INT,
password VARCHAR(255),
location VARCHAR(255),
role varchar(255)
);

-- Backup table for seller_port


CREATE TABLE seller_port_backup (
port_id INT,
password VARCHAR(255),
location varchar(255),
role varchar(255)
);

-- Backup table for products


CREATE TABLE products_backup (
product_id INT,
product_name VARCHAR(255),
quantity INT,
price FLOAT,
seller_id INT
);

-- Backup table for orders


CREATE TABLE orders_backup (
order_id INT,
product_id INT,
consumer_port_id INT,
quantity INT,
order_date TIMESTAMP,
order_placed BOOLEAN,
shipped BOOLEAN,
out_for_delivery BOOLEAN,
delivered BOOLEAN
);

-- Backup table for reported products


CREATE TABLE reported_products_backup (
report_id INT,
consumer_port_id INT,
product_id INT,
issue_type VARCHAR(255),
solution ENUM('solved', 'pending'),
report_date TIMESTAMP
);

-- Trigger for consumer_port


DELIMITER //

CREATE TRIGGER after_insert_consumer_port


AFTER INSERT ON consumer_port
FOR EACH ROW
BEGIN
INSERT INTO consumer_port_backup (port_id, password, location, role)
VALUES (NEW.port_id, NEW.password, NEW.location, NEW.role);
END//

DELIMITER ;

-- Trigger for seller_port


DELIMITER //

CREATE TRIGGER after_insert_seller_port


AFTER INSERT ON seller_port
FOR EACH ROW
BEGIN
INSERT INTO seller_port_backup (port_id, password, location, role)
VALUES (NEW.port_id, NEW.password, NEW.location, NEW.role);
END //

DELIMITER ;

-- Trigger for products


DELIMITER //

CREATE TRIGGER after_insert_products


AFTER INSERT ON products
FOR EACH ROW
BEGIN
INSERT INTO products_backup (product_id, product_name, quantity, price,
seller_id)
VALUES (NEW.product_id, NEW.product_name, NEW.quantity, NEW.price,
NEW.seller_id);
END //

DELIMITER ;

-- Trigger for orders


DELIMITER //

CREATE TRIGGER after_insert_orders


AFTER INSERT ON orders
FOR EACH ROW
BEGIN
INSERT INTO orders_backup (order_id, product_id, consumer_port_id, quantity,
order_date, order_placed, shipped, out_for_delivery, delivered)
VALUES (NEW.order_id, NEW.product_id, NEW.consumer_port_id, NEW.quantity,
NEW.order_date, NEW.order_placed, NEW.shipped, NEW.out_for_delivery,
NEW.delivered);
END //

DELIMITER ;

-- Trigger for reported_products


DELIMITER //

CREATE TRIGGER after_insert_reported_products


AFTER INSERT ON reported_products
FOR EACH ROW
BEGIN
INSERT INTO reported_products_backup (report_id, consumer_port_id, product_id,
issue_type, solution, report_date)
VALUES (NEW.report_id, NEW.consumer_port_id, NEW.product_id, NEW.issue_type,
NEW.solution, NEW.report_date);
END //

DELIMITER ;

-- Trigger for UPDATE on consumer_port


DELIMITER //
CREATE TRIGGER after_update_consumer_port
AFTER UPDATE ON consumer_port
FOR EACH ROW
BEGIN
INSERT INTO consumer_port_backup (port_id, password, location, role)
VALUES (NEW.port_id, NEW.password, NEW.location, NEW.role);
END //
DELIMITER ;

-- Trigger for DELETE on consumer_port


DELIMITER //
CREATE TRIGGER after_delete_consumer_port
AFTER DELETE ON consumer_port
FOR EACH ROW
BEGIN
INSERT INTO consumer_port_backup (port_id, password, location, role)
VALUES (OLD.port_id, OLD.password, OLD.location, OLD.role);
END //
DELIMITER ;

-- Trigger for UPDATE on seller_port


DELIMITER //
CREATE TRIGGER after_update_seller_port
AFTER UPDATE ON seller_port
FOR EACH ROW
BEGIN
INSERT INTO seller_port_backup (port_id, password, location, role)
VALUES (NEW.port_id, NEW.password, NEW.location, NEW.role);
END //
DELIMITER ;

-- Trigger for DELETE on seller_port


DELIMITER //
CREATE TRIGGER after_delete_seller_port
AFTER DELETE ON seller_port
FOR EACH ROW
BEGIN
INSERT INTO seller_port_backup (port_id, password, location, role)
VALUES (OLD.port_id, OLD.password, OLD.location, OLD.role);
END //
DELIMITER ;

-- Trigger for UPDATE on products


DELIMITER //
CREATE TRIGGER after_update_products
AFTER UPDATE ON products
FOR EACH ROW
BEGIN
INSERT INTO products_backup (product_id, product_name, quantity, price,
seller_id)
VALUES (NEW.product_id, NEW.product_name, NEW.quantity, NEW.price,
NEW.seller_id);
END //
DELIMITER ;

-- Trigger for DELETE on products


DELIMITER //
CREATE TRIGGER after_delete_products
AFTER DELETE ON products
FOR EACH ROW
BEGIN
INSERT INTO products_backup (product_id, product_name, quantity, price,
seller_id)
VALUES (OLD.product_id, OLD.product_name, OLD.quantity, OLD.price,
OLD.seller_id);
END //
DELIMITER ;

-- Trigger for UPDATE on orders


DELIMITER //
CREATE TRIGGER after_update_orders
AFTER UPDATE ON orders
FOR EACH ROW
BEGIN
INSERT INTO orders_backup (order_id, product_id, consumer_port_id, quantity,
order_date, order_placed, shipped, out_for_delivery, delivered)
VALUES (NEW.order_id, NEW.product_id, NEW.consumer_port_id, NEW.quantity,
NEW.order_date, NEW.order_placed, NEW.shipped, NEW.out_for_delivery,
NEW.delivered);
END //
DELIMITER ;

-- Trigger for DELETE on orders


DELIMITER //
CREATE TRIGGER after_delete_orders
AFTER DELETE ON orders
FOR EACH ROW
BEGIN
INSERT INTO orders_backup (order_id, product_id, consumer_port_id, quantity,
order_date, order_placed, shipped, out_for_delivery, delivered)
VALUES (OLD.order_id, OLD.product_id, OLD.consumer_port_id, OLD.quantity,
OLD.order_date, OLD.order_placed, OLD.shipped, OLD.out_for_delivery,
OLD.delivered);
END //
DELIMITER ;
-- Trigger for UPDATE on reported_products
DELIMITER //
CREATE TRIGGER after_update_reported_products
AFTER UPDATE ON reported_products
FOR EACH ROW
BEGIN
INSERT INTO reported_products_backup (report_id, consumer_port_id, product_id,
issue_type, solution, report_date)
VALUES (NEW.report_id, NEW.consumer_port_id, NEW.product_id, NEW.issue_type,
NEW.solution, NEW.report_date);
END //
DELIMITER ;

-- Trigger for DELETE on reported_products


DELIMITER //
CREATE TRIGGER after_delete_reported_products
AFTER DELETE ON reported_products
FOR EACH ROW
BEGIN
INSERT INTO reported_products_backup (report_id, consumer_port_id, product_id,
issue_type, solution, report_date)
VALUES (OLD.report_id, OLD.consumer_port_id, OLD.product_id, OLD.issue_type,
OLD.solution, OLD.report_date);
END //
DELIMITER ;

-- Procedure for user registration with hashed password


DELIMITER //
CREATE PROCEDURE register_user(
IN p_port_id int,
IN p_password VARCHAR(255),
IN p_confirm_password VARCHAR(255),
IN p_location VARCHAR(255),
IN p_role VARCHAR(255)
)
BEGIN
DECLARE hashed_password VARCHAR(255);

-- Check if passwords match


IF p_password = p_confirm_password THEN
-- Hash the password
SET hashed_password = SHA2(p_password, 256);

-- Check if role is consumer


IF p_role = 'consumer' THEN
INSERT INTO consumer_port (port_id, password, location, role)
VALUES (p_port_id, hashed_password, p_location, p_role);
SELECT 'Consumer registered successfully';
ELSE
INSERT INTO seller_port (port_id, password, location, role)
VALUES (p_port_id, hashed_password, p_location, p_role);
SELECT 'Seller registered successfully';
END IF;
ELSE
SELECT 'Password does not match';
END IF;
END;
//
DELIMITER ;

-- Procedure for user login with hashed password verification


DELIMITER //

CREATE PROCEDURE login_user(


IN p_port_id INT,
IN p_password VARCHAR(255),
IN p_role VARCHAR(255)
)
BEGIN
DECLARE stored_password VARCHAR(255);

-- Check if role is consumer


IF p_role = 'consumer' THEN
SELECT password INTO stored_password FROM consumer_port WHERE port_id =
p_port_id;
ELSE
SELECT password INTO stored_password FROM seller_port WHERE port_id =
p_port_id;
END IF;

-- Verify the hashed password


IF stored_password IS NOT NULL AND stored_password = SHA2(p_password, 256) THEN
SELECT 'Login successful';
ELSE
SELECT 'Invalid credentials';
END IF;
END;
//

DELIMITER ;

You might also like