-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test commit for sahildev * test commit for rutudev * Initial test commit for tanmaydev * Test commit * 💩 add authentication * 🗃️ Add scripts for /create and /list of blogs * 🗃️ Add scripts for /update and /delete of blogs * ➕ Add body-parser dependency * added landing login reg pages * 💄 Add create view * 🚧 Add create and landing view and backend code * 💫 Add logo * Merge rutudev * 🎨 Structure blog routes * 🚚 Restructure auth routes #4 * 🚚 Restructure auth routes #4 * 🚚 Restructure auth routes #4 * 👽 Add auth middleware for every blog crud operation #6 * 🗃️ Resolve deprecation warning * ✅ correct auth middleware * 💄 Change in Register and login page #5 * 🗃️ Generalize database name #10 * 🐛 Login bug resolve * 💄 Add tui editor in create view #3 * 🔧 password validate * 💩 Add script for create blog * 🚧 validations * ✨ Update create blog script * 🚧 validations * 🍻 Done validations #15 #12 * ✨ Render Blog on seperate route * ✨ Implement back button #18 * 📱 Login view and validations * 🔥 Remove a temporary file * 🐛 Fix UI bugs #18 #21 * 🐛 Fix footer in log and reg #21 * commit * 💄 Connect landing to auth pages * 💄 Error message styling in auth pages #28 * ✨ Add partial views for blog cards #2 * 🐛 Fix route and changed file name #30 * ✨ Add explore page * Changes Logout #32 * ⚡ redirects * 💩 Connect user and blog * Connect user and blog schemas * Iss33 (#36) * 📝 Add cover image and badges #33 * 📝 Add steps to run locally #33 * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * ♻️ Remove typo * 🐛 Fix login and redirect page bug * ⚡ Secret in .env * ♻️ Remove comments and extra code #37 * 🗃️ Add author field in blogSchema * 💄 Add author name on card #42 * ♻️ Redirect to explore after login * ✨ Explore page patch * ✨ Add functionality to create button * ✅ myblogs #45 * 🔨 removes myblog test #45 * ✨ Frontend my blogs #50 * 💄 update ui for frontend myblogs #50 * ✨ Add edit and delete functionality to blogs * 👽 Integrate mailchimp * ⚡ adds 404 page * ✨ Add navbar dropdown and avatar #55 * ➕ Add migrate-mongo dependency * 📝 Update documentation * 🐛 Patch * ♻️ Refactor API to get latest blogs first * 🔒 Add DB_URI in env Co-authored-by: sahilambre <sahilws111@gmail.com> Co-authored-by: Rutu <barve.rutu@gmail.com> Co-authored-by: Rutu <62687761+rutu363@users.noreply.github.com> Co-authored-by: Sahil Ambre <59484827+sahilambre@users.noreply.github.com>
- Loading branch information
1 parent
952e3da
commit 3fdc0bc
Showing
80 changed files
with
9,159 additions
and
39 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 +1,2 @@ | ||
PORT="Your PORT value" | ||
PORT="Your PORT value" | ||
JWT = "Your JWT secret" |
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,4 +1,52 @@ | ||
# A Blogging website built with Nodejs | ||
<p align="center"> | ||
<img alt="cover-image" src="./public/img/coverImage.svg"> | ||
</p> | ||
<p align="center"> | ||
<img alt="GitHub closed issues" src="https://img.shields.io/github/issues-closed/tanmayc07/Blog-App?color=Blue"> | ||
|
||
[![Generic badge](https://img.shields.io/badge/Status-In_Progress-green.svg)](https://shields.io/) | ||
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) | ||
<img alt="Github status" src="https://img.shields.io/badge/status-In Progress-brightgreen"> | ||
|
||
<img alt="Github status" src="https://img.shields.io/badge/Nodejs->=12.0.0-brightgreen"> | ||
|
||
<img alt="Github status" src="https://img.shields.io/badge/license-MIT-brightgreen"> | ||
</p> | ||
<p> | ||
<h1 align="center">Think it. Write it</h1> | ||
<p align="center">A Blogging website built with Nodejs 🖋️</p> | ||
</p> | ||
|
||
|
||
|
||
### **How to run code locally** | ||
|
||
1. Clone the repository | ||
|
||
2. Download all the **packages** and it's **dependencies**. Open the terminal and type | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
3. Create `.env` file and insert proper **key values** (refer `.env.sample`). | ||
|
||
4. Install migrate-mongo globally | ||
|
||
```bash | ||
npm install -g migrate-mongo | ||
``` | ||
5. Migrate up | ||
|
||
```bash | ||
migrate-mongo up | ||
``` | ||
|
||
6. To **start** the development server run | ||
|
||
```bash | ||
npm run startDev | ||
``` | ||
|
||
|
||
<!-- [![Generic badge](https://img.shields.io/badge/Status-In_Progress-green.svg)](https://shields.io/) --> | ||
|
||
<!-- [![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) --> |
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,17 +1,48 @@ | ||
require("dotenv").config(); | ||
const routes = require("express").Router(); | ||
const mongoose = require("mongoose"); | ||
const express = require("express"); | ||
const routes = require("./routes"); | ||
|
||
const cors = require("cors"); | ||
const bodyParser = require("body-parser"); | ||
const blogRoutes = require("./routes/blogs/blogRoutes"); | ||
const authRoutes = require("./routes/auths/authRoutes"); | ||
const cookieParser = require("cookie-parser"); | ||
const PORT = process.env.PORT; | ||
const { requireAuth } = require("./middleware/authMiddleware"); | ||
const Index = require("./routes/Index"); | ||
const app = express(); | ||
const checkUser = require("./middleware/authMiddleware"); | ||
|
||
|
||
app.use(express.static(__dirname + "./public")); | ||
app.use(express.json()); | ||
app.post("/register",routes); | ||
app.use(authRoutes); | ||
app.set("view engine", "ejs"); | ||
app.set("views", "./views"); | ||
|
||
app.use(cookieParser()); | ||
app.use(cors()); | ||
app.use(express.static(__dirname + "/public")); | ||
app.use("/create", routes); | ||
app.use("/", routes); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
app.use("/auth", authRoutes); | ||
app.use("/blogs", blogRoutes); | ||
app.use("/",Index); | ||
|
||
app.set("views", "./views"); | ||
app.set("view engine", "ejs"); | ||
|
||
//app.get("/auth/login", checkUser, (req, res) => { | ||
// res.render("register"); | ||
//}); | ||
|
||
app.use((req, res, next) => { | ||
res.status(404).render("404page"); | ||
}); | ||
|
||
|
||
app.listen(PORT, () => { | ||
console.log(`Server started at port ${PORT}`); | ||
}); |
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,105 @@ | ||
var User = require("../models/user/User"); | ||
const conn = require("../config/database"); | ||
const bcrypt = require("bcryptjs"); | ||
const jwt = require("jsonwebtoken"); | ||
const checkUser = require("../middleware/authMiddleware"); | ||
|
||
const secret = process.env.JWT; | ||
|
||
const handleErrors = (err) => { | ||
console.log(err.message); | ||
let errors = { email: "", password: "" }; | ||
|
||
// incorrect email | ||
if (err.message === "Incorrect Email") { | ||
errors.email = "That email is not registered"; | ||
} | ||
|
||
// incorrect password | ||
if (err.message === "Incorrect Password") { | ||
errors.password = "That password is incorrect"; | ||
} | ||
if ( | ||
err.message === "user validation failed: password: Minimum 6 characters" | ||
) { | ||
errors.password = "Minimum 6 characters required"; | ||
} | ||
if (err.code === 11000) { | ||
errors.email = "That email is already taken"; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
|
||
const redirect = (req, res) => { | ||
res.redirect("/auth/login"); | ||
}; | ||
|
||
|
||
module.exports.register_get = (req, res) => { | ||
res.render("register"); | ||
}; | ||
|
||
module.exports.login_get = (req, res) => { | ||
res.render("login"); | ||
}; | ||
|
||
const maxAge = 3 * 24 * 60 * 60; | ||
|
||
|
||
const createToken = (id)=>{ | ||
return jwt.sign({ id },secret,{ | ||
expiresIn: maxAge | ||
}); | ||
}; | ||
|
||
module.exports.register_post = async (req, res) => { | ||
const { | ||
firstname, | ||
lastname, | ||
email, | ||
username, | ||
password, | ||
gender, | ||
DOB, | ||
} = req.body; | ||
try { | ||
const user = await User.createUser({ | ||
firstname, | ||
lastname, | ||
email, | ||
username, | ||
password, | ||
gender, | ||
DOB, | ||
}); | ||
|
||
res.status(200).json({}); | ||
} catch (err) { | ||
const errors = handleErrors(err); | ||
|
||
res.status(400).json({ errors }); | ||
} | ||
}; | ||
module.exports.login_post = async (req, res) => { | ||
const email = req.body.email; | ||
const password = req.body.password; | ||
|
||
try { | ||
const user = await User.login(email, password); | ||
const token = createToken(user._id); | ||
res.cookie("jwt", token, { httpOnly: true, maxAge: maxAge * 1000 }); | ||
res.status(200).json({ user: user._id }); | ||
} catch (err) { | ||
const errors = handleErrors(err); | ||
res.status(400).json({ errors }); | ||
} | ||
|
||
}; | ||
|
||
module.exports.logout_get = (req, res) => { | ||
res.cookie('jwt', '', { maxAge: 1 }); | ||
res.redirect('/'); | ||
} | ||
|
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,64 @@ | ||
const model = require("../config/database"); | ||
const blogModel = require("../models/blogapi/crud"); | ||
const userModel = require("../models/user/User"); | ||
|
||
module.exports = { | ||
createForm: function (req, res) { | ||
let user = { | ||
id: req.userid | ||
} | ||
res.render("create", {user:user}); | ||
}, | ||
createData: function (req, res) { | ||
const inputData = req.body; | ||
const userid = req.userid; | ||
userModel.getOneUser(userid, function(username){ | ||
inputData.author = username | ||
blogModel.createBlog(req, inputData, function (data) { | ||
userModel.updateBlog(req, data, function (data) { | ||
res.json(data); | ||
}); | ||
}); | ||
}) | ||
}, | ||
listMine: function (req, res) { | ||
const inputData = req.body; | ||
const userid = req.userid; | ||
userModel.getOneUser(userid, function(author){ | ||
inputData.author = author | ||
blogModel.listMine(author,function (data) { | ||
res.render("myBlogs", { data }); | ||
}); | ||
}) | ||
}, | ||
listAll: function (req, res) { | ||
blogModel.listAll(function (data) { | ||
res.render("explore", { data }); | ||
}); | ||
}, | ||
listData: function (req, res) { | ||
const id = req.params.id | ||
blogModel.listBlog(id, function (data) { | ||
res.render("blog", { data }); | ||
}); | ||
}, | ||
getUpdate: function(req, res){ | ||
const id = req.params.id | ||
blogModel.listBlog(id, function(data){ | ||
res.render("update", { data: JSON.stringify(data), blogid:req.params.id }) | ||
}) | ||
}, | ||
updateData: function (req, res) { | ||
var inputData = req.body; | ||
var blogID = req.params.id; | ||
blogModel.updateBlog(inputData, blogID, function (data) { | ||
res.json(data); | ||
}); | ||
}, | ||
deleteData: function (req, res) { | ||
var blogID = req.params.id; | ||
blogModel.deleteBlog(blogID, function (data) { | ||
res.send(`Record deleted!`); | ||
}); | ||
}, | ||
}; |
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,3 @@ | ||
module.exports.Index = function (req, res) { | ||
res.render("home", { title: "Tanmay" }); | ||
res.render("landing"); | ||
}; |
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,23 @@ | ||
const jwt = require('jsonwebtoken'); | ||
const secret = process.env.JWT; | ||
const requireAuth = (req, res, next) => { | ||
const token = req.cookies.jwt; | ||
|
||
// check json web token exists & is verified | ||
if (token) { | ||
jwt.verify(token,secret, (err, decodedToken) => { | ||
if (err) { | ||
console.log(err.message); | ||
res.redirect('/auth/login'); | ||
} else { | ||
req.userid = decodedToken.id | ||
next(); | ||
} | ||
}); | ||
} else { | ||
res.redirect('/auth/login'); | ||
} | ||
}; | ||
|
||
|
||
module.exports = { requireAuth }; |
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,22 @@ | ||
const jwt = require('jsonwebtoken'); | ||
const secret = process.env.JWT; | ||
const checkUser = (req, res, next) => { | ||
const token = req.cookies.jwt; | ||
|
||
// check json web token exists & is verified | ||
if (token) { | ||
jwt.verify(token,secret, (err, decodedToken) => { | ||
if (err) { | ||
console.log(err.message); | ||
} else { | ||
res.redirect('/blogs/explore'); | ||
} | ||
}); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
|
||
|
||
|
||
module.exports = { checkUser }; |
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,30 @@ | ||
// In this file you can configure migrate-mongo | ||
|
||
const config = { | ||
mongodb: { | ||
// TODO Change (or review) the url to your MongoDB: | ||
url: "mongodb://localhost:27017/blog", | ||
|
||
// TODO Change this to your database name: | ||
databaseName: "blog", | ||
|
||
options: { | ||
useNewUrlParser: true, // removes a deprecation warning when connecting | ||
useUnifiedTopology: true, // removes a deprecating warning when connecting | ||
// connectTimeoutMS: 3600000, // increase connection timeout to 1 hour | ||
// socketTimeoutMS: 3600000, // increase socket timeout to 1 hour | ||
} | ||
}, | ||
|
||
// The migrations dir, can be an relative or absolute path. Only edit this when really necessary. | ||
migrationsDir: "migrations", | ||
|
||
// The mongodb collection where the applied changes are stored. Only edit this when really necessary. | ||
changelogCollectionName: "changelog", | ||
|
||
// The file extension to create migrations and search for in migration dir | ||
migrationFileExtension: ".js" | ||
}; | ||
|
||
// Return the config as a promise | ||
module.exports = config; |
Oops, something went wrong.