Pollify is an online voting system designed to simplify the electoral process through secure, intuitive features, two-factor authentication, and real-time data visualization.
- Project Overview
- Features
- Database Setup
- Apache Tomcat Setup
- Setting Up Database Connection
- Running Pollify
- Screenshots
Pollify enables a smooth, structured election process, making it ideal for online voting scenarios. The system supports different types of users with distinct functionalities, ensuring an organized, secure election.
- Admin: Manages the voting period, candidates, and final result declarations.
- Candidates: Submits manifestos, applies for candidacy, and participates in elections.
- Voters: Casts votes during active periods and views election results.
- Voting Period Control: Enables controlled start and end times for voting.
- Real-Time Statistics: Displays data on total votes, turnout ratio, and more.
- Two-Factor Authentication (2FA): Sends OTP to email for user identity verification.
- Result Visualization: Post-election, displays winner with vote percentages and turnout statistics.
- Controlled Voting Periods: The voting room only opens during active voting periods, set by the admin.
- Real-Time Status: Shows the current turnout ratio and total votes cast as the election progresses.
- One-User-One-Vote Enforcement: Users can only vote once per election to ensure fairness.
- Winner Calculation: After voting concludes, the system calculates the winner based on vote count and percentage.
- Turnout Ratio: Displays the turnout percentage to indicate the level of participation.
- Visibility Options: Only the admin can initially view results, with an option to declare them publicly.
- OTP Verification: An OTP is sent to users’ registered emails during signup to ensure they are real users.
- Time-Limited OTPs: Each OTP has a 10-minute validity period to prevent misuse.
- Security Enhancement: Ensures only verified users participate in voting.
- Manifesto Submission: Candidates can create, edit, and manage their manifestos.
- Candidacy Application: Users can apply to become candidates for the current voting period.
- Admin Approval: Only approved candidates are eligible to appear on the ballot.
- Registration Confirmation: Users receive an email confirmation upon successful registration.
- Voting Period Announcements: Admins can notify users about upcoming and ongoing voting periods.
- Result Notifications: Admins can announce results, along with individual notifications for candidates.
- Win/Loss Alerts for Candidates: Candidates receive personalized notifications about the outcome.
-
Create the Database
CREATE DATABASE pollify; USE pollify;
-
Create Required Tables
-
Users
table:CREATE TABLE Users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(100) UNIQUE NOT NULL, email VARCHAR(150) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, role ENUM('admin', 'voter', 'candidate') NOT NULL, status ENUM('pending', 'approved') DEFAULT 'pending', voted BOOLEAN DEFAULT FALSE, phone_number VARCHAR(20), otp_code VARCHAR(10), otp_expiry DATETIME, manifesto TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
VotingPeriod
table:CREATE TABLE VotingPeriod ( id INT AUTO_INCREMENT PRIMARY KEY, start_time DATETIME, end_time DATETIME, is_active BOOLEAN DEFAULT FALSE );
-
Votes
table:CREATE TABLE Votes ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, candidate_id INT, voting_period_id INT, vote_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE, FOREIGN KEY (candidate_id) REFERENCES Users(id) ON DELETE CASCADE, FOREIGN KEY (voting_period_id) REFERENCES VotingPeriod(id) ON DELETE CASCADE );
-
Results
table:CREATE TABLE Results ( id INT AUTO_INCREMENT PRIMARY KEY, voting_period_id INT, winner_candidate_id INT, total_votes INT DEFAULT 0, winner_percentage DECIMAL(5,2), turnout_ratio DECIMAL(5,2), start_time DATETIME, end_time DATETIME, declared_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (voting_period_id) REFERENCES VotingPeriod(id) ON DELETE SET NULL, FOREIGN KEY (winner_candidate_id) REFERENCES Users(id) ON DELETE SET NULL );
-
CandidateApplications
table:CREATE TABLE CandidateApplications ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, voting_period_id INT, status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending', submission_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE, FOREIGN KEY (voting_period_id) REFERENCES VotingPeriod(id) ON DELETE CASCADE );
-
-
Create MySQL Events
-
Activate Voting Period:
CREATE EVENT activate_voting_period ON SCHEDULE EVERY 1 MINUTE DO UPDATE VotingPeriod SET is_active = TRUE WHERE start_time <= NOW() AND end_time > NOW();
-
Deactivate Voting Period:
CREATE EVENT deactivate_voting_period ON SCHEDULE EVERY 1 MINUTE DO UPDATE VotingPeriod SET is_active = FALSE WHERE end_time <= NOW();
-
-
Download Apache Tomcat 9
Download Tomcat 9 from the official website: Apache Tomcat 9 Download. -
Clone the Pollify Repository
Clone thePollify
GitHub repository into thewebapps
folder of your Apache Tomcat directory:git clone https://github.com/lakshitcodes/pollify.git /path/to/tomcat/webapps/pollify
-
Create Database Credentials File
Inside the directory/pollify/WEB-INF/classes/com/pollify
, create a file namedDBCredentials.java
with the following code. Replace"your_username"
and"your_password"
with your actual MySQL credentials:package com.pollify; public class DBCredentials { private static final String DB_URL = "jdbc:mysql://localhost:3306/pollify"; private static final String DB_USER = "your_username"; private static final String DB_PASS = "your_password"; public static String getDbUrl() { return DB_URL; } public static String getDbUser() { return DB_USER; } public static String getDbPass() { return DB_PASS; } }
-
Download Required Libraries
Place the following JAR files in the
lib
folder of your Apache Tomcat directory:servlet-api.jar
mysql-connector.jar
javax.mail.jar
activation-1.1.1.jar
These libraries are essential for servlet handling, MySQL database connectivity, and email functionality.
-
Compile Java Files
If Apache Tomcat is installed in the
Downloads
folder of your macOS system, run the following command to compile all.java
files inpollify/WEB-INF/classes/com/pollify
:javac -cp "/Users/lakshitjain/Downloads/apache-tomcat-9.0.96/lib/*:/Users/lakshitjain/Downloads/apache-tomcat-9.0.96/lib/mysql-connector-j-9.0.0.jar:/Users/lakshitjain/Downloads/apache-tomcat-9.0.96/lib/activation-1.1.1.jar" /Users/lakshitjain/Downloads/apache-tomcat-9.0.96/webapps/pollify/WEB-INF/classes/com/pollify/*.java
-
Start Apache Tomcat
Navigate to the
bin
directory of your Apache Tomcat installation and start the server to deploy the Pollify application:cd /path/to/tomcat/bin ./startup.sh
-
Access Pollify
Open a web browser and go to
http://localhost:8080/pollify
to access the Pollify application.
Once the Apache Tomcat server is up and running, you can access Pollify at http://localhost:8080/pollify
. Register as a user or log in as an admin to explore the various functionalities of the system.