Skip to content

Repository files navigation

QR-based Entry-Exit System (Backend)

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.


Table of Contents


Technologies Used

  • 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.

Features

  • User registration and authentication with password hashing.
  • QR code-based entry and exit logging.
  • Secure RESTful API for frontend communication.

Installation

Prerequisites

  • Node.js and npm installed.
  • MongoDB installed or access to a cloud-based MongoDB instance.

Steps

  1. Clone the repository:
    git clone 
  2. Navigate to the project directory:
    cd qr-entry-exit-system-backend
  3. Install dependencies:
    npm install
  4. Create a .env file with the following variables:
    MONGO_URI=your_mongodb_connection_string
    PORT=5000
    JWT_SECRET=your_secret_key
    
  5. Start the server:
    npm start

API Endpoints

Authentication

Register User

POST /api/auth/register

  • Request Body:
    {
      "name": "John Doe",
      "email": "john@example.com",
      "password": "password123"
    }
  • Response:
    {
      "message": "User registered successfully"
    }

Login User

POST /api/auth/login

  • Request Body:
    {
      "email": "john@example.com",
      "password": "password123"
    }
  • Response:
    {
      "token": "jwt_token_here"
    }

Entry/Exit Logging

Log Entry or Exit

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"
      }
    }

Code Snippets

User Schema with Mongoose

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);

Future Enhancements

  • 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.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages