Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password reset and api for user authentication #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions backend/controllers/alumni.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import Alumni from '../models/Alumni.model.js';

const getAlumni = async (req, res) => {
try {
const AlumniData = await Alumni.find().sort({ createdAt: -1 });
res.status(200).json({
message: 'Alumni data retrieved successfully',
alumni: AlumniData
});

} catch (error) {
console.error(error);
}
}

const addAlumni = async (req, res) => {
try {
const newAlumni = await Alumni({ ...req.body });
await newAlumni.save();
res.send(201).json({
message: 'Alumni added successfully',
alumni: newAlumni
});
} catch (error) {
console.error(error);
}
}

const deleteAlumni = async (req, res) => {
try {
const { email } = req.params;
const deletedAlumni = await Alumni.findOneAndDelete({email: email});
if (!deletedAlumni) {
return res.status(404).json({
message: 'Alumni not found'
});
}else{
res.status(200).json({
message: 'Alumni deleted successfully',
alumni: deletedAlumni
});
}
} catch (error) {
console.error(error);

}
}

const getSingleAlumni = async (req, res) => {
try {
const { email } = req.params;
const alumni = await Alumni.findOne({email: email});
if (!alumni) {
return res.status(404).json({
message: 'Alumni not found'
});
}else{
res.status(200).json({
message: 'Alumni retrieved successfully',
alumni: alumni
});
}
} catch (error) {
console.error(error);

}
}

const updateAlumni = async (req, res) => {
try {
const { email } = req.params;

// Validate if the email parameter is provided
if (!email) {
return res.status(400).json({
message: 'Email is required to update an alumni record',
});
}

const updateAlumni = await Alumni.findOneAndUpdate(
{ email: email },
req.body,
{ new: true }
);

if (!updateAlumni) {
return res.status(404).json({
message: 'Alumni not found',
});
} else {
res.status(200).json({
message: 'Alumni updated successfully',
alumni: updateAlumni,
});
}
} catch (error) {
console.error(error);
res.status(500).json({
message: 'An error occurred while updating the alumni',
});
}
};


export default {
getAlumni,
addAlumni,
deleteAlumni,
getSingleAlumni,
updateAlumni
}
1 change: 0 additions & 1 deletion backend/controllers/jobs.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const jobList = async (req, res) => {
}
};

import JobPosting from '../models/jobPosting.js';

export const jobRelevanceScoreUpvote = async (req, res) => {
try {
Expand Down
72 changes: 72 additions & 0 deletions backend/controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import User from '../models/user.model.js';

const signup = async (req, res) => {
try {
const newStudent = await User({ ...req.body });
newStudent.save();
res.send(201).json({
message: 'Student added successfully',
student: newStudent
});
} catch (error) {
console.error(error);
}
}

const login = async (req, res) => {
try {
const { email, password } = req.body;
const studentData = User.findOne({ email: email });
if(!studentData){
return res.status(404).json({
message: 'Student not found'
});
}
if(studentData.password !== password){
return res.status(401).json({
message: 'Invalid password'
});
}
res.status(200).json({
message: 'Login successful',
student: studentData
});

} catch (error) {
console.error(error);
}
}

const updateProfile = async (req, res) => {
try {
const data = req.body;
const { email } = data;
const updateStudent = await User.findOneAndUpdate({ email: email }, { ...data });
res.status(200).json({
message: 'Profile updated successfully',
student: updateStudent
});
} catch (error) {
console.error(error);
}
}

const deleteProfile = async (req, res) => {
try {
const { email } = req.body;
const deletedStudent = await User.findOneAndDelete({ email: email });
res.send(200).json({
message: 'Student deleted successfully',
student: deletedStudent
});
} catch (error) {
console.error(error);
}
}

export default {
signup,
login,
updateProfile,
deleteProfile
}
9 changes: 5 additions & 4 deletions backend/models/Alumni.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ const alumniSchema = new mongoose.Schema({
linkedin:{
type: String,
},
InstituteId:{
instituteId:{
type: String,
required: true
},
MobileNumber:{
mobileNumber:{
type:Number,
required:true
},
Email:{
email:{
type: String,
required: true
required: true,
unique: true
}
})

Expand Down
17 changes: 17 additions & 0 deletions backend/routes/alumni.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import express from 'express';
import alumniController from '../controllers/alumni.controller.js';

const { getAlumni, addAlumni, deleteAlumni, getSingleAlumni, updateAlumni } = alumniController;
const router = express.Router();

router.get('/getAlumni', getAlumni);

router.post('/addAlumni', addAlumni);

router.delete('/deleteAlumni/:email', deleteAlumni);

router.get('/getSingleAlumni/:email', getSingleAlumni);

router.put('/updateAlumni/:email', updateAlumni);

export default router;
4 changes: 2 additions & 2 deletions backend/routes/router.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//importing all the necessary dependencies
import express from "express";
import {jobCreate,jobUpdate,jobRelevanceScoreUpvote,jobRelevanceScoreDownvote} from "../controllers/jobs.controllers.js"
import {jobCreate,jobUpdate,jobRelevanceScoreUpvote,jobRelevanceScoreDownvote, jobDelete, jobList} from "../controllers/jobs.controllers.js"
import { ViewRes } from "../controllers/studentview.js";
import SavedApplications from "../../frontend/src/pages/Savedapplications.jsx";


//using the router
const router = express.Router();
Expand Down
15 changes: 15 additions & 0 deletions backend/routes/user.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express';
import userController from '../controllers/user.controller.js';
const router = express.Router();

const { signup, login, updateProfile, deleteProfile } = userController;

router.post('/signup', signup);

router.get('/login', login);

router.put('/updateProfile', updateProfile);

router.delete('/deleteProfile', deleteProfile);

export default router;
4 changes: 4 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ app.use(express.json());
const port = 3000;

//apis
import alumniRoute from "./routes/alumni.route.js";
import userRouter from "./routes/user.route.js";
app.use("/api", router);
app.use("/api/alumni", alumniRoute);
app.use("/api/users", userRouter);

//listener
app.listen(port, () => {
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/api/alumniAPI/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Alumni Management API

This document outlines how to add or update alumni data in the database using a CSV file and the `alumniAPI` function.

## Prerequisites

1. You need a CSV file containing alumni data.
2. Ensure your backend is running and connected to the database.
3. Use the correct backend URL for API requests.
4. Email should be unique for each row of CSV file
5. After add email to database you can't change it
6. import alumniAPI from alumniAPI.js file in frontend file

## Setup

1. **CSV File Format:**
Your CSV file should include the following columns:
- `id` (for updating existing records)
- Other fields (e.g., name, email, etc.)

## APIs

1. GET ALL ALUMNI ::: "http://localhost:3000/api/alumni/getAlumni"
2. POST ALUMNI ::: aluminAPI("csv_file", "add")
3. UPDATE ALUMNI ::: alumniAPI("csv_file", "update")
4. DELETE ALUMIN ::: "http://localhost:3000/api/alumni/deleteAlumni/:email"
5. GET SINGLE ALUMNI ::: "http://localhost:3000/api/alumni/getSingleAlumni/:email"
41 changes: 41 additions & 0 deletions frontend/src/api/alumniAPI/alumniAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


const alumniAPI = (asvData, status) => {
if (!['update', 'add'].includes(status)) {
console.error('Invalid status! Use either "update" or "add".');
return;
}

asvData.array.forEach( async (row) => {
try{
if(status === "add"){
// Add alumni
const response = await fetch('http://localhost:3000/api/alumni/addAlumni', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(row)
});
const data = await response.json();
console.log(data);
}
if(status === "update"){
// Update alumni
const response = await fetch(`http://localhost:3000/api/alumni/updateAlumni/${row.email}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(row)
});
const data = await response.json();
console.log(data);
}
}catch (error){
console.error(error)
}
});
}

export default alumniAPI;