The Registration System is a robust backend service designed for managing user registrations, sending seminar pass emails, and verifying user attendance for events. Built using Node.js, Express, and MongoDB, it ensures efficient user management with authentication and encryption mechanisms.
Ensure the following are installed on your system:
- Node.js (>= 14.x)
- MongoDB (local or cloud instance)
- Git
-
Clone the repository:
git clone <repository-url> cd RegistrationSystem
-
Install dependencies:
npm install
-
Setup Environment Variables: Create a
.envfile in the root directory and configure it as follows:MONGODB_URI=<your-mongodb-uri> PORT=<your-port> JWT_SECRET=<your-jwt-secret> EMAIL_USER=<your-email> EMAIL_PASSWORD=<your-email-password> AES_SECRET=<your-aes-secret> AES_IV=<your-aes-iv>
-
Start the server:
npm start
The server will run on the specified port in
.envor default to5000.
http://localhost:<PORT>/api
-
POST /register - Register a new user.
- Request Body:
{ "name": "John Doe", "collegeEmail": "[email protected]", "collegeId": "12345678901", "year": "3rd", "department": "CSE", "contactNumber": "1234567890", "whatsappNumber": "0987654321" } - Response:
{ "message": "User created successfully", "newUser": { ... }, "token": "<encrypted-token>" }
- Request Body:
-
GET /users - Fetch all registered users.
- Response:
[ { ... }, { ... } ]
- Response:
-
GET /users/:id - Retrieve user details by college ID.
- Response:
{ "message": "User found", "user": { ... } }
- Response:
-
PUT /users/update/:id - Update user information by college ID.
- Request Body: (Only fields that need updating should be sent)
{ "name": "John Doe", "year": "4th", "department": "CSE", "contactNumber": "9876543210" } - Response:
{ "user": { ... }, "message": "User updated successfully" }
- Request Body: (Only fields that need updating should be sent)
-
GET /users/verify/:encryptedToken - Verify user check-in using an encrypted token.
- Response:
{ "message": "User checked in successfully", "user": { ... } }
- Response:
-
GET /registrations/count - Get the total count of registered users.
- Response:
{ "count": 100 }
- Response:
File: models/userModel.js
const mongoose = require("mongoose");
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
collegeEmail: { type: String, required: true, unique: true },
collegeId: { type: String, required: true, unique: true },
year: { type: String, required: true },
department: { type: String, required: true },
contactNumber: { type: String, required: true },
whatsappNumber: { type: String, required: true },
token: { type: String },
isPresent: { type: Boolean, default: false },
isSeminarAttendee: { type: Boolean, default: false }
}, { timestamps: true });
module.exports = mongoose.model("User", userSchema);File: controllers/userController.js
Handles user registration, retrieval, updating, and email functionalities.
Handles email notifications, such as sending seminar passes and verification emails.
Prevents server sleep by periodically sending requests to keep it active.
Ensure the following variables are correctly configured in your .env file:
MONGODB_URI=<your-mongodb-uri>
PORT=<your-port>
JWT_SECRET=<your-jwt-secret>
EMAIL_USER=<your-email>
EMAIL_PASSWORD=<your-email-password>
AES_SECRET=<your-aes-secret>
AES_IV=<your-aes-iv>- Fork the repository.
- Create a feature branch:
git checkout -b feature-branch
- Implement your changes.
- Commit your changes:
git commit -m "Add new feature" - Push to your branch:
git push origin feature-branch
- Create a Pull Request on GitHub.