-
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 branch 'Bitbox-Connect:main' into main
- Loading branch information
Showing
14 changed files
with
312 additions
and
117 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# BitBox | ||
|
||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![GitHub issues](https://img.shields.io/github/issues/Anuj3553/codecontri.svg)](https://github.com/yourusername/codecontri/issues) | ||
[![GitHub stars](https://img.shields.io/github/stars/Anuj3553/codecontri.svg)](https://github.com/yourusername/codecontri/stargazers) | ||
[![GitHub forks](https://img.shields.io/github/forks/Anuj3553/codecontri.svg)](https://github.com/yourusername/codecontri/network) | ||
[![GitHub issues](https://img.shields.io/github/issues/Anuj3553/BitBox.svg)](https://github.com/Anuj3553/BitBox/issues) | ||
[![GitHub stars](https://img.shields.io/github/stars/Anuj3553/BitBox.svg)](https://github.com/Anuj3553/BitBox/stargazers) | ||
[![GitHub forks](https://img.shields.io/github/forks/Anuj3553/BitBox.svg)](https://github.com/Anuj3553/BitBox/network) | ||
|
||
## 🎯 Overview | ||
|
||
|
@@ -41,15 +41,37 @@ npm install npm@latest -g | |
1. **Clone the repository**: | ||
|
||
```sh | ||
git clone https://github.com/your_username/BitBox.git | ||
git clone https://github.com/Anuj3553/BitBox.git | ||
``` | ||
|
||
2. **Install NPM packages**: | ||
2. **Install NPM packages** for both client and server: | ||
|
||
```sh | ||
cd client | ||
npm install | ||
``` | ||
|
||
```sh | ||
cd server | ||
npm install | ||
``` | ||
|
||
### Running the Project | ||
|
||
1. **Open the first terminal** and start the client: | ||
|
||
```sh | ||
cd client | ||
npm run dev | ||
``` | ||
|
||
2. **Open the second terminal** and start the server: | ||
|
||
```sh | ||
cd server | ||
nodemon index.js | ||
``` | ||
|
||
--- | ||
|
||
## 🤝 Contributing | ||
|
@@ -92,6 +114,14 @@ For any inquiries, feel free to reach out: | |
|
||
## 🏆 Main Contributors | ||
|
||
- **Harshit7492** | ||
- **Anuj Verma** | ||
- **Jitendra Kumar** | ||
Email: [[email protected]](mailto:[email protected]) | ||
|
||
**Highlighted Main Contributors:** | ||
|
||
```diff | ||
+ 🌟 Harshit7492: Backend API development and database optimizations. | ||
+ 🌟 Jitendra Kumar: Significant contributions in frontend development. | ||
``` | ||
|
||
--- |
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,71 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams, useNavigate } from 'react-router-dom'; | ||
|
||
const host = "http://localhost:5000"; | ||
|
||
const VerifyEmail = () => { | ||
const { token } = useParams(); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [isVerified, setIsVerified] = useState(null); | ||
const [modalMessage, setModalMessage] = useState(''); | ||
const [showModal, setShowModal] = useState(false); | ||
const navigate = useNavigate(); | ||
|
||
const handleVerification = () => { | ||
fetch(`${host}/api/auth/verify/${token}`, { | ||
method: 'POST', | ||
}) | ||
.then(response => { | ||
if (response.status === 200) { | ||
setIsVerified(true); | ||
setModalMessage('Email verified! You can now log in.'); | ||
} else if (response.status === 400) { | ||
setIsVerified(false); | ||
setModalMessage('Invalid or expired verification link'); | ||
} | ||
setShowModal(true); | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
handleVerification(); | ||
}, [token]); | ||
|
||
const handleModalClose = () => { | ||
setShowModal(false); | ||
if (isVerified) { | ||
navigate('/login'); | ||
}else{ | ||
navigate('/signup') | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Verify Your Email</h2> | ||
{isLoading ? ( | ||
<p>Verifying your email...</p> | ||
) : ( | ||
<button onClick={handleVerification} disabled={isLoading}> | ||
{isLoading ? 'Verifying...' : 'Verify Email'} | ||
</button> | ||
)} | ||
|
||
{/* Modal Implementation */} | ||
{showModal && ( | ||
<div className="modal-overlay"> | ||
<div className="modal-content"> | ||
<h3>{modalMessage}</h3> | ||
<button onClick={handleModalClose}>Close</button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default VerifyEmail; |
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 |
---|---|---|
@@ -1,3 +1,44 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@tailwind utilities; | ||
|
||
|
||
.modal-overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */ | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
z-index: 1000; | ||
} | ||
|
||
.modal-content { | ||
width: 400px; | ||
background-color: white; | ||
padding: 40px; | ||
border-radius: 10px; | ||
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1); | ||
text-align: center; | ||
} | ||
|
||
.modal-content h3 { | ||
margin-bottom: 15px; | ||
} | ||
|
||
.modal-content button { | ||
background-color: #007bff; | ||
color: white; | ||
padding: 10px 20px; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
.modal-content button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
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,2 @@ | ||
EMAIL_USER="" | ||
EMAIL_PASS="" |
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 |
---|---|---|
|
@@ -21,4 +21,6 @@ env.local | |
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
yarn-error.log* | ||
|
||
|
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,118 @@ | ||
const User = require("../Models/User"); | ||
const bcrypt = require("bcrypt"); | ||
|
||
|
||
const nodemailer = require('nodemailer'); | ||
const crypto = require('crypto'); | ||
|
||
// Signup route | ||
const createUser= async (req, res) => { | ||
const { name, email, password } = req.body; | ||
|
||
// Create a new user (save in your database) | ||
const user = new User({ name,email, password, verified: false }); | ||
await user.save(); | ||
|
||
// Generate verification token | ||
const verificationToken = crypto.randomBytes(32).toString('hex'); | ||
|
||
// Save the verification token to the user (or in another collection) | ||
user.verificationToken = verificationToken; | ||
await user.save(); | ||
|
||
// Send verification email | ||
const transporter = nodemailer.createTransport({ | ||
service: 'Gmail', | ||
auth: { | ||
user: process.env.EMAIL_USER, // Use the environment variable | ||
pass: process.env.EMAIL_PASS, // Use the environment variable | ||
}, | ||
}); | ||
|
||
const verificationLink = `http://localhost:5173/verify/${verificationToken}`; | ||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: email, | ||
subject: 'Email Verification', | ||
text: `Click this link to verify your email: ${verificationLink}`, | ||
}; | ||
|
||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
return res.status(500).send('Error sending verification email'); | ||
} | ||
res.status(200).send('Signup successful! Please check your email for verification link.'); | ||
}); | ||
}; | ||
|
||
|
||
const verifyToken = async (req, res) => { | ||
const { token } = req.params; | ||
|
||
try { | ||
// Find the user by verification token | ||
const user = await User.findOne({ verificationToken: token }); | ||
if (!user) { | ||
return res.status(400).json({ success: false, message: 'Invalid or expired verification link' }); | ||
} | ||
console.log(user) | ||
|
||
// Mark user as verified | ||
user.verified = true; | ||
user.verificationToken = undefined; // Clear the token after verification | ||
await user.save(); | ||
|
||
// Optionally send a success message to the client | ||
res.status(200).json({ success: true, message: 'Email verified successfully!' }); | ||
|
||
// Redirect to the frontend's home page or login page | ||
// You can choose where to redirect the user after verification | ||
res.redirect('http://localhost:5173/'); // Replace with your frontend home URL | ||
} catch (err) { | ||
console.error(err); | ||
res.status(500).json({ success: false, message: 'Server error. Please try again later.' }); | ||
} | ||
}; | ||
|
||
|
||
|
||
const forgetpassword = async (req, res) => { | ||
|
||
try { | ||
const { email, password } = req.body; | ||
// Find the user by email | ||
const user = await User.findOne({ email }); // Use findOne instead of find | ||
if (!user) { | ||
return res | ||
.status(404) | ||
.json({ success: false, message: "User not found" }); | ||
} | ||
|
||
// Hash the new password | ||
const salt = await bcrypt.genSalt(10); | ||
const secPass = await bcrypt.hash(password, salt); | ||
|
||
// Update the user's password | ||
user.password = secPass; | ||
|
||
// Save the updated user | ||
await user.save(); | ||
|
||
return res.json({ | ||
success: true, | ||
message: "Password updated successfully", | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res | ||
.status(500) | ||
.json({ success: false, message: "Internal server error" }); | ||
} | ||
}; | ||
|
||
|
||
module.exports = { | ||
forgetpassword, | ||
createUser, | ||
verifyToken, | ||
}; |
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
Oops, something went wrong.