This repository contains the backend part of the QR-based Entry-Exit System, which securely handles user authentication, QR code data processing, and entry/exit logging for university campuses.
- Node.js: JavaScript runtime for server-side development.
- Express.js: Web framework for building REST APIs.
- MongoDB: NoSQL database for storing user and log data.
- Mongoose: ODM (Object Data Modeling) library for MongoDB.
- bcrypt.js: Library for password hashing.
- User registration and authentication with password hashing.
- QR code-based entry and exit logging.
- Secure RESTful API for frontend communication.
- Node.js and npm installed.
- MongoDB installed or access to a cloud-based MongoDB instance.
- Clone the repository:
git clone
- Navigate to the project directory:
cd qr-entry-exit-system-backend
- Install dependencies:
npm install
- Create a
.env
file with the following variables:MONGO_URI=your_mongodb_connection_string PORT=5000 JWT_SECRET=your_secret_key
- Start the server:
npm start
POST /api/auth/register
- Request Body:
{ "name": "John Doe", "email": "[email protected]", "password": "password123" }
- Response:
{ "message": "User registered successfully" }
POST /api/auth/login
- Request Body:
{ "email": "[email protected]", "password": "password123" }
- Response:
{ "token": "jwt_token_here" }
POST /api/logs
- Headers:
{ "Authorization": "Bearer jwt_token_here" }
- Request Body:
{ "qrCode": "sample_qr_code_data" }
- Response:
{ "message": "Entry logged successfully", "log": { "userId": "user_id_here", "timestamp": "2025-01-12T10:00:00Z" } }
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const userSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
}
});
userSchema.pre('save', async function (next) {
if (!this.isModified('password')) return next();
const salt = await bcrypt.genSalt(10);
this.password = await bcrypt.hash(this.password, salt);
next();
});
module.exports = mongoose.model('User', userSchema);
- Role-Based Access Control: Implement admin roles for better management.
- Activity Reporting: Add detailed reports for entry/exit logs.
- WebSockets: Enable real-time updates for logs.
This project is licensed under the MIT License. See the LICENSE file for more information.