-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #435 from ShivanshPlays/AdminBackend
Admin backend #435
- Loading branch information
Showing
9 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useState } from 'react'; | ||
import faqimage from "../assets/images/vector-faq-frequently-asked-questions.png" | ||
const FAQSection = () => { | ||
const [activeIndex, setActiveIndex] = useState(null); | ||
|
||
const faqs = [ | ||
{ question: "What is Bitbox?", answer: "Bitbox is a collaborative platform for developers to share and find solutions to coding projects, enhancing project development and troubleshooting." }, | ||
{ question: "Who can use Bitbox?", answer: "Bitbox is suitable for developers, students, and tech enthusiasts seeking collaboration on coding projects or guidance." }, | ||
{ question: "How can I submit a project on Bitbox?", answer: "Sign up and click 'Submit Project' to share details and engage with the community." }, | ||
{ question: "Is Bitbox free to use?", answer: "Yes, Bitbox is currently free for project submission and collaboration." }, | ||
{ question: "Can I get feedback on my code?", answer: "Yes, community members can provide feedback and suggestions on projects." }, | ||
{ question: "What types of projects are welcome on Bitbox?", answer: "All coding projects across languages and frameworks are welcome on Bitbox." }, | ||
{ question: "How do I report inappropriate content?", answer: "Click the 'Report' button on any content, and our moderators will review it." }, | ||
{ question: "Can I connect with other users?", answer: "Yes, you can comment on projects and join discussions to collaborate." }, | ||
{ question: "Is Bitbox limited to specific programming languages?", answer: "No, Bitbox supports projects in various programming languages and frameworks." }, | ||
{ question: "How do I stay updated on new projects?", answer: "Sign up for notifications or follow popular projects for updates on the latest content." } | ||
]; | ||
|
||
|
||
const handleToggle = (index) => { | ||
setActiveIndex(activeIndex === index ? null : index); | ||
}; | ||
|
||
return ( | ||
<div className="p-6 bg-gray-100 rounded-lg mt-4 dark:from-gray-900 dark:to-gray-800 mb-4"> | ||
<h2 className="text-[3rem] font-semibold mb-4 mt-20">Frequently Asked Questions</h2> | ||
|
||
<div className='flex justify-around'> | ||
<div> | ||
<img src={faqimage} alt="Description w-1/2" className='object-cover'style={{ width: '600px', }}/> | ||
</div> | ||
<div className="space-y-4 w-1/2"> | ||
{faqs.map((faq, index) => ( | ||
<div key={index} className="bg-white rounded-lg shadow-md"> | ||
<div | ||
className="p-4 cursor-pointer bg-gray-200 rounded-t-lg hover:bg-gray-300 transition duration-200" | ||
onClick={() => handleToggle(index)} | ||
> | ||
<h3 className="text-lg font-medium">{faq.question}</h3> | ||
</div> | ||
{activeIndex === index && ( | ||
<div className="p-4 bg-gray-50 rounded-b-lg"> | ||
<p>{faq.answer}</p> | ||
</div> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FAQSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const Admin = require("../Models/Admin"); | ||
const bcrypt = require("bcrypt"); | ||
var jwt = require("jsonwebtoken"); | ||
const nodemailer = require("nodemailer"); | ||
const crypto = require("crypto"); | ||
require('dotenv').config(); // Load environment variables from .env file | ||
const { body, validationResult } = require("express-validator"); | ||
const login= async (req, res) => { | ||
let success = false; | ||
console.log("see"); | ||
|
||
// Check for validation errors | ||
const errors = validationResult(req); | ||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ errors: errors.array() }); | ||
} | ||
|
||
const { email, password } = req.body; | ||
|
||
try { | ||
let user = await Admin.findOne({ email }); | ||
|
||
// If user does not exist | ||
if (!user) { | ||
return res.status(400).json({ | ||
success, | ||
error: "Please try to login with correct credentials", | ||
}); | ||
} | ||
|
||
// Compare provided password with stored password | ||
const passwordCompare = await bcrypt.compare(password, user.password); | ||
|
||
if (!passwordCompare) { | ||
return res.status(400).json({ | ||
success, | ||
error: "Please try to login with correct credentials", | ||
}); | ||
} | ||
|
||
// Create JWT payload | ||
const data = { | ||
user: { | ||
id: user.id, | ||
}, | ||
}; | ||
|
||
// Sign the JWT | ||
const authtoken = jwt.sign(data, process.env.JWT_SECRET); | ||
// Send token in response to be stored in localStorage on the client | ||
return res.status(200).json({ success: true, authtoken }); | ||
} catch (error) { | ||
console.error(error.message); | ||
return res.status(500).send("Internal Server Error"); | ||
} | ||
} | ||
const createAdmin=async (req, res) => { | ||
const { name, email, password } = req.body; | ||
|
||
try { | ||
const saltRounds = 10; | ||
const hashedPassword = await bcrypt.hash(password, saltRounds); | ||
|
||
// Create a new user (save in your database) | ||
const user = new Admin({ name, email, password: hashedPassword }); | ||
|
||
await user.save(); | ||
return res.status(201).json({ success: true, message: "Admin created successfully"}) | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: error.message }); | ||
} | ||
}; | ||
const logout=async (req,res)=>{ | ||
// Optionally, you can clear the cookie if you're using cookies for sessions | ||
res.clearCookie('connect.sid'); // Replace 'connect.sid' with your session cookie name | ||
|
||
// Send a success response | ||
return res.status(200).json({ message: 'Successfully logged out.' }); | ||
|
||
} | ||
const dashboard= null; | ||
|
||
|
||
module.exports = { | ||
login, | ||
createAdmin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const mongoose = require("mongoose"); | ||
const { Schema } = mongoose; | ||
|
||
const AdminSchema = new Schema( | ||
{ | ||
imageUrl: { | ||
type: String, | ||
required: false | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
match: [/\S+@\S+\.\S+/, 'Please enter a valid email address'], | ||
}, | ||
password: { | ||
type: String, | ||
required: true, | ||
minlength: 8 // Minimum length for password | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const Admin = mongoose.model('Admin', AdminSchema); | ||
module.exports = Admin; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
const express = require("express"); | ||
var jwt = require("jsonwebtoken"); | ||
const {login,createAdmin}= require("../Controllers/adminController") | ||
const User = require("../Models/Admin.js"); | ||
const bcrypt = require("bcrypt"); | ||
const router = express.Router(); | ||
require("dotenv").config(); | ||
const { body, validationResult } = require("express-validator"); | ||
const { OAuth2Client } = require("google-auth-library"); | ||
const rateLimit = require("express-rate-limit"); | ||
require('dotenv').config(); // Load environment variables from .env file | ||
|
||
|
||
router.post("/login",login) | ||
router.post("/create",createAdmin) | ||
|
||
module.exports = router; |