Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/arpita-32/WordWise
Browse files Browse the repository at this point in the history
  • Loading branch information
arpita-32 committed Oct 30, 2024
2 parents c1fa304 + 114ddff commit 98aab05
Show file tree
Hide file tree
Showing 47 changed files with 6,939 additions and 3,284 deletions.
51 changes: 51 additions & 0 deletions Carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
document.addEventListener('DOMContentLoaded', function () {
const slides = document.querySelector('.slides');
const radioButtons = document.querySelectorAll('input[name="radio-btn"]');
const labels = document.querySelectorAll('.manual-btn');
const prevButton = document.getElementById('prevSlide');
const nextButton = document.getElementById('nextSlide');
let currentSlide = 0;

function showSlide(index) {
slides.style.transform = `translateX(-${index * 14.29}%)`;
radioButtons[index].checked = true;
updateActiveLabel(index);
}

function updateActiveLabel(index) {
labels.forEach((label, i) => {
if (i === index) {
label.classList.add('active');
} else {
label.classList.remove('active');
}
});
}

function nextSlide() {
currentSlide = (currentSlide + 1) % radioButtons.length;
showSlide(currentSlide);
}
function prevSlide() {
currentSlide = (currentSlide - 1 + radioButtons.length) % radioButtons.length;
showSlide(currentSlide);
}

// Add click event listeners to radio buttons
radioButtons.forEach((radio, index) => {
radio.addEventListener('click', () => {
currentSlide = index;
showSlide(currentSlide);
});
});

// Add click event listeners to Prev and Next buttons
prevButton.addEventListener('click', prevSlide);
nextButton.addEventListener('click', nextSlide);

// Show first slide initially
showSlide(0);

// Automatic slide change
setInterval(nextSlide, 5000);
});
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

---

## 📈 GitHub Repository Stats
| 🌟 **Stars** | 🍴 **Forks** | 🐛 **Issues** | 🔔 **Open PRs** | 🔕 **Closed PRs** | 🛠️ **Languages** |**Contributors** |
|--------------|--------------|---------------|-----------------|------------------|------------------|------------------|
| ![GitHub stars](https://img.shields.io/github/stars/ANSHIKA-26/WordWise) | ![forks](https://img.shields.io/github/forks/ANSHIKA-26/WordWise) | ![issues](https://img.shields.io/github/issues/ANSHIKA-26/WordWise?color=32CD32) | ![pull requests](https://img.shields.io/github/issues-pr/ANSHIKA-26/WordWise?color=FFFF8F) | ![Closed PRs](https://img.shields.io/github/issues-pr-closed/ANSHIKA-26/WordWise?color=20B2AA) | ![Languages](https://img.shields.io/github/languages/count/ANSHIKA-26/WordWise?color=20B2AA) | ![Contributors](https://img.shields.io/github/contributors/ANSHIKA-26/WordWise?color=00FA9A) |

## Featured In

<table>
Expand Down
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# MONGO_URI=mongodb://localhost:27017/bloggingdb
MONGO_URI=mongodb://localhost:27017/bloggingdb
JWT_SECRET=scijyasfy7dsvegdffvbfbfgg435tgrsnbgfgn
PORT=5000
Expand Down
8 changes: 7 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import express from "express";
import dotenv from "dotenv";
import connectDB from "./utils/db.js";
import blogRoutes from "./routes/blogRoutes.js";
import userRoutes from "./routes/userRoutes.js";
import userRoutes from "./routes/userRoutes.js";
import feedbackRoutes from "./routes/feebackroute.js";
import cors from "cors";

dotenv.config();
const app = express();
connectDB();

app.use(express.json());

// to avoid cross origin errror
app.use(cors());

app.use("/api/users", userRoutes);
app.use("/api/blogs", blogRoutes);
app.use("/api/feedback", feedbackRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
Expand Down
36 changes: 36 additions & 0 deletions backend/controllers/blogController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Blog from "../models/blog.js";
import Comment from "../models/comment.js";

export const createBlog = async (req, res) => {
try {
Expand Down Expand Up @@ -52,3 +53,38 @@ export const getSingleBlog = async (req, res) => {
res.status(500).json({ message: error.message });
}
};

export const saveComment = async (req, resp) => {
try {
const { name, comment } = req.body;

if (!name || !comment) {
return resp.status(400).send({
message: "all fields are required",
success: false,
});
}

const newcomment = await new Comment({
name: name,
comment: comment,
});

newcomment.save();

if (newcomment) {
return resp.status(200).send({
success: true,
message: "new comment added",
newcomment,
});
}
} catch (error) {
console.log(error);
return resp.status(500).send({
success: false,
message: "internal server error",
error,
});
}
};
24 changes: 24 additions & 0 deletions backend/controllers/feedbackcontroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import feedback from "../models/feedback.js";

export async function saveFeedback(req, resp) {
try {
const { name, userfeedback, email, rating } = req.body;

if (!name || !userfeedback || !email || typeof rating !== "number") {
return resp.status(400).json({ message: "All fields are required." });
}

const newfeedback = new feedback({ name, userfeedback, email, rating });

// Save feedback to the database
await newfeedback.save();

// Respond with success message
resp
.status(201)
.json({ message: "Feedback saved successfully!", newfeedback });
} catch (error) {
console.error("Error saving feedback:", error);
resp.status(500).json({ message: "Failed to save feedback.", error });
}
}
123 changes: 123 additions & 0 deletions backend/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import User from "../models/user.js";
import jwt from "jsonwebtoken";
import dotenv from "dotenv";
import nodemailer from "nodemailer";
import bcrypt from "bcryptjs";
dotenv.config();

// Generate JWT token
Expand Down Expand Up @@ -99,3 +101,124 @@ export const getAllUsers = async (req, res) => {
res.status(500).json({ message: error.message });
}
};

export function ForgotPassWordEmail(req, resp) {
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "your email id",
pass: "your password",
},
});

const mailOptions = {
from: "your email id",
to: req.body.Email,
subject: "WordWise Reset Password",
html: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Reset</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
color: #333;
margin: 0;
padding: 0;
}
.email-container {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
color: #333;
}
p {
font-size: 16px;
line-height: 1.5;
color: #666;
}
.button-container {
text-align: center;
margin-top: 20px;
}
.button {
background-color: #4CAF50;
color: #ffffff;
padding: 12px 20px;
border: none;
border-radius: 4px;
text-decoration: none;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="email-container">
<h2>Password Reset Request</h2>
<p>Hello,</p>
<p>We received a request to reset your password. Click the button below to proceed with resetting your password.</p>
<div class="button-container">
<a href="https://wordwise-k9ho.onrender.com/resetpass.html" class="button">Reset Password</a>
</div>
<p>Thank you,<br>Team WordWise</p>
</div>
</body>
</html>
`,
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log("Error sending email: " + error);
resp.status(500).send("Error sending email");
} else {
console.log("Email sent: " + info.response);
resp.status(200).send("Form data sent successfully");
}
});
}

export async function ResetPassword(req, resp) {
try {
const { password, email } = req.body;

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

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

user.password = hashedPassword;
await user.save();

resp
.status(200)
.json({ success: true, message: "Password reset successfully" });
} catch (error) {
console.error("Error resetting password:", error);
resp.status(500).json({
success: false,
message: "An error occurred. Please try again later.",
});
}
}
21 changes: 21 additions & 0 deletions backend/models/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { mongoose } from "mongoose";

const commentSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
trim: true,
},
comment: {
type: String,
required: true,
trim: true,
},
},
{ timestamps: true }
);

const Comment = mongoose.model("Comment", commentSchema);

export default Comment;
29 changes: 29 additions & 0 deletions backend/models/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { mongoose } from "mongoose";

const feedbackSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
trim: true,
},
userfeedback: {
type: String,
required: true,
trim: true,
},
email: {
type: String,
required: true,
},
rating: {
type: Number,
required: true,
},
},
{ timestamps: true }
);

const feedback = mongoose.model(" feedback", feedbackSchema);

export default feedback;
Loading

0 comments on commit 98aab05

Please sign in to comment.