Skip to content

Commit

Permalink
announcements feat added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansh101112 committed Jul 5, 2024
2 parents f4e09f4 + 53b4556 commit 42152ef
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 427 deletions.
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ Share your feedback and insights with the Smart Savers community to improve the
Effortlessly scan QR codes to access instant product information.
## Others:
Explore additional features including product management sections.
## Announcements tab
- In the admin dashboard we have made the announcement tab in which the admin can make announcements regarding the updates and tech needs so that the registered users or developers can have the email regarding the updation in the web application.
---
Expand All @@ -107,10 +111,10 @@ Explore additional features including product management sections.
## Get Started
1. After successfully setting up the project you can view the project on port `3000`
2. Give access to the camera and log in with your credentials as well.
2. Give access to the camera and log in with your credentials.
3. Now scan the particular product QR and get all the details.
4. If the software couldn't find your product then our database is missing the product details inn it.
5. Add that particular product by following the above steps as mentioned above.
4. If the software couldn't find your product then our database is missing the product details in it.
5. Add that particular product by following the abovementioned steps.

### Setup and Installation

Expand Down Expand Up @@ -138,13 +142,35 @@ Explore additional features including product management sections.
### Backend Setup
- Navigate through the `backend` folder
- Setup `.env` file and set `MONGO_URL` and other dev dependencies regarding in `.env.sample` and set your own .env file
- Make the conection string and copy the string in the mongodb compass and start server in the mongodb cluster in compassUI or on website respectively
- Setup `.env` file and set `MONGO_URL` and other dev dependencies regarding in `.env.sample` and set your .env file
- Make the connection string and copy the string in the Mongodb compass and start the server in the MongoDB cluster in compassUI or on the website respectively
- Now install all dependencies required for backend setup `npm install`
- Now run the server with `npm start`
- Your backend server will be running on `PORT: 6352`
### Running Tests
To ensure the robustness of our application, we use Jest and Supertest for testing.
#### Setting up Jest and Supertest
1. **Install Dependencies**
```bash
npm install jest supertest --save-dev
2. Create Test Files Create test files in the tests folder (or another preferred directory).
3. Writing Tests Use Jest and Supertest to write your tests.
4. Run Tests To run the tests, use the following command: `npm test`
5. You can also add a script in your package.json for convenience:
`
"scripts": {
"test": "jest"
}`
### Contributing
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
Expand All @@ -160,6 +186,12 @@ We love your input! We want to make contributing to this project as easy and tra
It can be seen here: https:vercel.com/new/clone?repository-url=https://github.com/usha-madithati/esmart.github.io
- Check and test whole website application and its functionality

### Backend Deployment:
- For Backend setup and server changes we have different approach in our project.
- We have the server on a different repo on which the specific interested project contributors have access to it.
- Soon we will add the functionality of adding the specific interested contributors through our web application.


Now if you tested the application and believe that it has your functionality or bug has been fixed as well then raise the PR(Pull Request).

Try our web application here: [https://esmartgit.vercel.app/](https://esmart-github-io-oq3w.vercel.app/)
Expand Down
4 changes: 3 additions & 1 deletion backend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# sample env file with some imp info

# PORT = 6352
# MONGO_URL = YOUR_MONGODB_URL
# MONGO_URL = YOUR_MONGODB_URL
# EMAIL=""
# EMAIL_PASSWORD="" //this is app password
6 changes: 6 additions & 0 deletions backend/Schemas/User.Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const UserSchema = new mongoose.Schema({
type: String,
default: "3 days",
},
resetPasswordToken: {
type: String,
},
resetPasswordExpires: {
type: Date,
},
});

const User = mongoose.model("User", UserSchema);
Expand Down
92 changes: 91 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import jwt from "jsonwebtoken";
import bcrypt from "bcrypt";
import User from "./Schemas/User.Schema.js";
import client from "./twilioConfig.js";
import nodemailer from 'nodemailer';
import crypto from "crypto"; // Add this line
import nodemailer from "nodemailer"; // Add this line

dotenv.config();

Expand Down Expand Up @@ -361,6 +362,95 @@ app.post("/login", async (req, res) => {
res.status(500).send({ message: "Error logging in", error: error.message });
}
});
// Configure nodemailer for email sending
const transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: process.env.EMAIL,
pass: process.env.EMAIL_PASSWORD,
},
});

// Route to handle forgot password
app.post("/forgot-password", async (req, res) => {
const { email } = req.body;

try {
const user = await User.findOne({ email });
if (!user) {
return res.status(404).json({ message: "User not found" });
}

const token = crypto.randomBytes(20).toString("hex");

user.resetPasswordToken = token;
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour

await user.save();

const resetURL = `http://localhost:3000/user/reset-password/${token}`;

const mailOptions = {
to: user.email,
from: process.env.EMAIL,
subject: "Password Reset",
text: `You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n
Please click on the following link, or paste this into your browser to complete the process:\n\n
${resetURL}\n\n
If you did not request this, please ignore this email and your password will remain unchanged.\n`,
};

transporter.sendMail(mailOptions, (err, response) => {
if (err) {
console.error("There was an error: ", err);
res.status(500).json({ message: "Error sending email", error: err });
} else {
res.status(200).json({
success: true,
message: "Password reset email sent successfully",
});
}
});
} catch (error) {
res.status(500).json({ message: "Server error", error: error.message });
}
});

// Route to handle reset password
app.post("/user/reset-password/:token", async (req, res) => {
const { token } = req.params;
const { password } = req.body;

try {
const user = await User.findOne({
resetPasswordToken: token,
resetPasswordExpires: { $gt: Date.now() },
});

if (!user) {
return res.status(400).json({ message: "Password reset token is invalid or has expired." });
}

const hashedPassword = await bcrypt.hash(password, 10);

user.password = hashedPassword;
user.resetPasswordToken = undefined;
user.resetPasswordExpires = undefined;

await user.save();

res.status(200).json({
success: true,
message: "Password reset successful!",
});
} catch (error) {
res.status(500).json({ message: "Server error", error: error.message });
}
});





// Start the server
const server = app.listen(PORT, () => {
Expand Down
10 changes: 10 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.4.0",
<<<<<<< HEAD
"nodemailer": "^6.9.13",
=======
"nodemailer": "^6.9.14",
>>>>>>> 53b4556520ccfc77bbb053ad39f15f4f69ced03a
"nodemon": "^3.1.1",
"twilio": "^5.1.1"
},
Expand Down
Loading

0 comments on commit 42152ef

Please sign in to comment.