Skip to content

Commit

Permalink
last change
Browse files Browse the repository at this point in the history
  • Loading branch information
avulapuneethkumarreddy committed Mar 15, 2024
1 parent 73aca9c commit 43c1054
Show file tree
Hide file tree
Showing 76 changed files with 26,108 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added Backend/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions Backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DATABASE_URL=mongodb+srv://Ankulraja2003:[email protected]/youTubeLayer
PORT=4000
JWT_SECRET=Ytlayer


CLOUD_NAME=dkoezhi9u
API_KEY=166197153345613
API_SECRET=vYHji2_e3axVjn7VmdytsjoTmaE
19 changes: 19 additions & 0 deletions Backend/Config/Cloudinary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

const cloudinary= require('cloudinary').v2;

const cloudinaryConnect = async (req, res) => {
try {
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET,
});
console.log("cloudConnect successfully");
} catch (err) {
console.log(err);
console.log("Not Connected With Cloudinary");
}
};

module.exports = cloudinaryConnect;

18 changes: 18 additions & 0 deletions Backend/Config/Database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const mongoose = require("mongoose");
require("dotenv").config();

const dbConnect = async (req, res) => {
mongoose
.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(console.log("Connected to database"))
.catch(() => {
console.log("Failed to connect to database");
process.exit(1);
});
};


module.exports = dbConnect;
144 changes: 144 additions & 0 deletions Backend/Controller/Autherise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
const User =require("../Model/User");
const bcrypt = require('bcrypt');
const jwt = require("jsonwebtoken")
require('dotenv').config()

exports.signup=async(req,res)=>{
try{
const {firstName,lastName,email,password,confirmPassword,accountType} = req.body;
if(!firstName || !lastName || !email || !password || !confirmPassword || !accountType){
return res.status(404).json({
success: false,
message:"Fill Are require fields"
})
}

if(password !== confirmPassword){
return res.status(404).json({
success: false,
message:"Password Not Match"
})
}
const existingUser = await User.findOne({ email});

if(existingUser){
return res.status(400).json({
success: false,
message:"User already exists"
})
}
console.log(password);
const hashPassword = await bcrypt.hash(password,10)
if(!hashPassword){
return res.status(400).json({
success: false,
message:"Hashing the password failed"
})
}
console.log(hashPassword);
const newUser = await User.create({
firstName,
lastName,
email,
password:hashPassword,
accountType,
image: `https://api.dicebear.com/5.x/initials/svg?seed=${firstName}${lastName}`
});

const existUser = await User.findOne({ email });

const payload = {
email: existUser.email,
accountType: existUser.accountType,
id: existUser._id,
};
const token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "2h",
});
existUser.token = token;
existUser.password = undefined;

const options = {
expires: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000),
httpOnly: true,
};
return res.cookie("token", token, options).status(200).json({
success: true,
message: 'Login successful',
token,
existUser,
});


}
catch(e){
return res.status(400).json({
success: false,
message:"Error in SignUp"
})
}
}




exports.login=async(req,res)=>{
try {
const { email, password } = req.body;
if (!email || !password) {
return res.status(404).json({
success: false,
message: "Email or Password empty"
});
}

const existUser = await User.findOne({ email });
if (!existUser) {
return res.status(400).json({
success: false,
message: 'Email not registered',
});
}



if (!await bcrypt.compare(password, existUser.password)) {
return res.status(404).json({
success: false,
message: 'Password is incorrect',
});
}



const payload = {
email: existUser.email,
accountType: existUser.accountType,
id: existUser._id,
};
const token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "2h",
});


existUser.token = token;
existUser.password = undefined;

const options = {
expires: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000),
httpOnly: true,
};
return res.cookie("token", token, options).status(200).json({
success: true,
message: 'Login successful',
token,
existUser,
});
} catch (e) {
console.log(e.message)
return res.status(500).json({
success: false,
message: 'Login Failure, please try again',
});
}
};
103 changes: 103 additions & 0 deletions Backend/Controller/EdData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const YtSchema = require("../Model/YtSchema");
const uploadFile = require("../Utility/Upload");

exports.getAllTaskData = async (req, res) => {
try {
let data = [];
const { category, status, email } = req.body;
console.log("status", status);
console.log(category);
console.log(email);
if (category === "All") {
if (status === "All") {
data = await YtSchema.find({
$or: [
{ status: status },
{
requestedMail: { $ne: email },
assignEmail: { $in: [null, "", undefined] },
},
],
});
console.log("GetALLTaskData", data);

// data = await YtSchema.find({requestedMail:{$ne:email},assignEmail:{$ne:email} });
} else if (status === "Requested") {
data = await YtSchema.find({ requestedMail: email, status: status });
} else if (status === "Assigned") {
data = await YtSchema.find({ status: status, assignEmail: email });
}
} else {
data = await YtSchema.find({ ytCategory: category, status: status });
}
// console.log("3")
// console.log("Data Print",data)
// console.log("4")
console.log(data);
return res.status(200).json({
success: true,
data,
message: "Video Upload Data Found",
});
} catch (e) {
console.log(e.message);
return res.status(500).json({
success: false,
message: "Upload Video Data Not Found",
});
}
};

exports.updateEditodVideo = async (req, res) => {
try {
console.log("3");
const { ytId } = req.body;
console.log("4");

const { editedVideoUrl } = req.files;
console.log("5");
const response = await uploadFile(editedVideoUrl, "YoutubeLayer");
const result = await YtSchema.findByIdAndUpdate(
ytId,
{ $push: { editedVideoList: response.secure_url } },
{ new: true }
);
console.log("6");

return res.status(200).json({
success: true,
message: "Edited Video Upload Successfully",
result,
});
} catch (e) {
console.log(e);
return res.status(500).json({
success: false,
message: "Edited Video Not Upload",
});
}
};

exports.deleteEditodVideo = async (req, res) => {
try {
const { content, ytId } = req.body;
console.log("Comming in deleteod video");
console.log(ytId);
console.log(content);
const output = await YtSchema.findByIdAndUpdate(
ytId,
{ $pull: { editedVideoList: content } },
{ new: true }
);
console.log(output);
return res.status(200).json({
success: true,
message: "Edited Video deleted successfully",
});
} catch (e) {
return res.status(500).json({
success: false,
message: "Edited Video Not deleted ",
});
}
};
Loading

0 comments on commit 43c1054

Please sign in to comment.