- Backend: https://iitb-m6cl.onrender.com
- Frontend: https://spontaneous-salamander-50a3b0.netlify.app
- Live Demo: https://drive.google.com/file/d/1qM2P7ekb9DnqmDUB3df7Ph-bYIpQjSRR/view?usp=sharing
{
username:"tajaya28",
password:"aA1!@#$%"
}
Here is the markdown documentation for the provided API controllers:
This project consists of a Node.js backend server and a React frontend, integrated with authentication, file uploads, and user management features.
- Backend: Node.js, Express.js, MongoDB, Mongoose, JWT, Bcrypt,
- Frontend: React, Chakra UI, reCAPTCHA
- Other Libraries: Validator, Multer (for file uploads)
Create a .env
file in the root of the project with the following variables:
SECRET= Your secret key
MONGO= Your mongo uri
PORT=8000
CAPTCHA_SECRET= Your captcha secret of v2 invisible
Create a .env
file in the root of the frontend directory with the following variable:
VITE_SECRET= Your recaptcha secret
VITE_SERVER= Your server link
- Node.js installed on your machine
- MongoDB installed and running locally
-
Clone the repository:
git clone https://github.com/yourusername/your-repo.git
-
Navigate to the backend directory:
cd your-repo/backend
-
Install dependencies:
npm install
-
Set up environment variables as described in the Environment Variables section.
-
Start the server:
npm start
The backend server should now be running at http://localhost:8000
.
-
Navigate to the frontend directory:
cd ../frontend
-
Install dependencies:
npm install
-
Set up environment variables as described in the Environment Variables section.
-
Start the frontend development server:
npm run dev
The frontend should now be running at http://localhost:5173
.
POST /api/auth/signup
Registers a new user in the system.
{
"username": "string",
"email": "string",
"password": "string",
"dateOfBirth": "string (date in ISO format)",
"photo": {
"data": "Buffer",
"contentType": "string"
},
"cv": {
"data": "Buffer",
"contentType": "string"
},
"recaptchaToken": "string"
}
{
"ok": true,
"message": "Signup successful! Please log in."
}
-
400 Bad Request
{ "ok": false, "message": "reCAPTCHA verification failed" }
{ "ok": false, "message": "All fields are required." }
{ "ok": false, "message": "Password is not strong" }
-
500 Internal Server Error
{ "ok": false, "message": "Signup failed!" }
POST /api/auth/login
Logs in a user or an admin and returns a JWT token.
{
"username": "string",
"password": "string",
"recaptchaToken": "string"
}
{
"ok": true,
"token": "string",
"isAdmin": "boolean",
"details": {
"_id": "string",
"username": "string",
"email": "string",
"dateOfBirth": "string (date in ISO format)",
"photo": {
"data": "string (base64)",
"contentType": "string"
},
"cv": {
"data": "string (base64)",
"contentType": "string"
}
}
}
-
400 Bad Request
{ "ok": false, "message": "reCAPTCHA verification failed" }
{ "ok": false, "message": "Invalid username or password." }
-
401 Unauthorized
{ "ok": false, "message": "Invalid username or password." }
{ "ok": false, "message": "Wait for admin to verify your account." }
-
500 Internal Server Error
{ "ok": false, "message": "Server error" }
photo
andcv
fields in the request body should be in Buffer format and include thecontentType
.- The password is hashed before storing in the database.
- The
isStrongPassword
function from thevalidator
library is used to ensure password strength. - The
verifyRecaptcha
service is used to validate the reCAPTCHA token. - The JWT token is generated using the
jsonwebtoken
library and is valid for 1 day. - Only verified users can log in. Admin verification is required before a user can log in.
Here is the markdown documentation for the provided API controllers:
GET /api/users
Retrieves a list of all users. Only accessible by admins. Supports pagination and filtering by verification status.
page
(optional): Page number for pagination (default: 1).limit
(optional): Number of users per page (default: 10).isVerified
(optional): Filter users by verification status (true
orfalse
).
{
"ok": true,
"users": [
{
"_id": "string",
"username": "string",
"email": "string",
"dateOfBirth": "string"
}
],
"totalPages": "number",
"currentPage": "number"
}
-
403 Forbidden
{ "ok": false, "message": "Unauthorized: Only admins can access all users" }
-
500 Internal Server Error
{ "ok": false, "message": "Server error" }
GET /api/users/:id
Retrieves the details of a user by their ID. Users can only access their own details, while admins can access any user's details.
id
: The ID of the user.
{
"ok": true,
"user": {
"_id": "string",
"username": "string",
"email": "string",
"dateOfBirth": "string",
"photo": {
"data": "string (base64)",
"contentType": "string"
},
"cv": {
"data": "string (base64)",
"contentType": "string"
}
}
}
-
403 Forbidden
{ "ok": false, "message": "Unauthorized: Only admins or its own user can access." }
-
404 Not Found
{ "ok": false, "message": "User not found" }
-
500 Internal Server Error
{ "ok": false, "message": "Server error" }
PUT /api/users/:id
Updates the details of a user by their ID. Users can update their own details except isAdmin
and isVerified
. Admins can update any user's details except isAdmin
.
id
: The ID of the user.
{
"username": "string (optional)",
"email": "string (optional)",
"password": "string (optional)",
"dateOfBirth": "string (optional)",
"photo": {
"data": "Buffer (optional)",
"contentType": "string (optional)"
},
"cv": {
"data": "Buffer (optional)",
"contentType": "string (optional)"
},
"isVerified": "boolean (optional, only for admin)"
}
{
"ok": true,
"message": "Updated Successfully"
}
-
403 Forbidden
{ "ok": false, "message": "Unauthorized: You or Admin can only update your own profile" }
-
404 Not Found
{ "ok": false, "message": "User not found" }
-
400 Bad Request
{ "ok": false, "message": "Not a strong password" }
-
500 Internal Server Error
{ "ok": false, "message": "Server error" }
DELETE /api/users/:id
Deletes a user by their ID. Users can delete their own account, while admins can delete any user's account.
id
: The ID of the user.
{
"ok": true,
"message": "User deleted successfully"
}
-
403 Forbidden
{ "ok": false, "message": "Unauthorized: You can only delete your own account" }
-
404 Not Found
{ "ok": false, "message": "User not found" }
-
500 Internal Server Error
{ "ok": false, "message": "Server error" }
- The
isStrongPassword
function from thevalidator
library is used to ensure password strength. - Users can only access and update their own details, except for admins who have broader access.
- JWT authentication middleware should be used to protect these routes and ensure only authorized users can access them.