Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
.env
66 changes: 66 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require("dotenv").config();
const express = require("express"),
app = express(),
mongoose = require("mongoose"),
bodyParser = require("body-parser");
(expressSantizer = require("express-sanitizer")),
(methodOverride = require("method-override")),
(passport = require("passport")),
(localStrategy = require("passport-local")),
(flash = require("connect-flash"));

const blogRoutes = require("./routes/blog"),
authRoutes = require("./routes/auth");

const User = require("./models/user");

app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(expressSantizer());
app.use(methodOverride("_method"));
app.use(flash());

// PASSPORT Configuration
app.use(
require("express-session")({
secret: "Who knows what is this?!",
resave: false,
saveUninitialized: false,
})
);
app.use(passport.initialize());
app.use(passport.session());
passport.use(new localStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// FLASH Middleware
app.use((req, res, next) => {
res.locals.user = req.user;
res.locals.success = req.flash("success");
res.locals.error = req.flash("error");
next();
});

app.use("/blogs", blogRoutes);
app.use("/", authRoutes);

mongoose
.connect(process.env.DB_CONNECT, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log("===DB Connected===");
})
.catch((err) => {
console.log(err);
});

app.listen(process.env.PORT || 3000);
18 changes: 18 additions & 0 deletions css/login.css

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

9 changes: 9 additions & 0 deletions css/login.css.map

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

16 changes: 16 additions & 0 deletions css/login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.container {
width: 30%;
padding: 2rem 3rem;
box-shadow: 0 0 8px 0 #aaa;
margin: auto;
text-align: center;
margin-top: 5em;

input {
display: block;
margin: auto;
width: 70%;
height: 2rem;
padding: 1rem;
}
}
39 changes: 39 additions & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Blog = require("../models/blog"),
User = require("../models/user");
exports.isLoggedIn = function (req, res, next) {
if (req.isAuthenticated()) {
return next();
}

req.flash("error", "Please log in first");
return res.redirect("/login");
};

exports.checkBlogAuthor = function (req, res, next) {
Blog.findById(req.params.id, (err, blog) => {
if (err || !blog) {
console.log(err);
req.flash("error", "Sorry! This blog does not exist");
return res.redirect("/blogs");
} else if (blog.author.id.equals(req.user._id)) {
next();
} else {
req.flash("error", "You do not have permission to do that");
return res.redirect("back");
}
});
};

exports.checkLoginInfo = function (req, res, next) {
User.findOne({ username: req.body.username }, (err, user) => {
if (err || !user) {
req.flash(
"error",
"This username does not exist. Please register first."
);
return res.redirect("/login");
}

next();
});
};
21 changes: 21 additions & 0 deletions models/blog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require("mongoose");

const blogSchema = new mongoose.Schema({
title: String,
body: String,
image: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},

name: String,
},
created: {
type: Date,
default: Date.now(),
},
});

module.exports = mongoose.model("Blog", blogSchema);
30 changes: 30 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");

const userSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
},
username: {
type: String,
required: true,
unique: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
// required: true,
},
},
{ timestamps: true }
);

userSchema.plugin(passportLocalMongoose);

module.exports = mongoose.model("User", userSchema);
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "ircblog",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@hapi/joi": "^17.1.1",
"body-parser": "^1.19.0",
"connect-flash": "^0.1.1",
"dotenv": "^8.2.0",
"ejs": "^3.1.2",
"express": "^4.17.1",
"express-sanitizer": "^1.0.5",
"express-session": "^1.17.1",
"method-override": "^3.0.0",
"mongoose": "^5.9.10",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^6.0.1"
}
}
109 changes: 109 additions & 0 deletions public/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>About Us | ITER ROBOTICS CLUB</title>
<link rel="stylesheet" href="./mainCSS/style.css" />
<link rel="stylesheet" href="./mainCSS/about.css" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<header>
<nav>
<div class="brand">
<a href="./index.html"
><img
class="logo"
src="https://static.wixstatic.com/media/fcb8e7_e1093d7e7fe6430a9b8c0184805d177d~mv2.png/v1/crop/x_322,y_0,w_606,h_629/fill/w_99,h_81,al_c,q_85,usm_0.66_1.00_0.01/IRC_1.webp
"
alt="logo"
/></a>
<a href="./index.html">
<h2 class="brand-title">ITER Robotics Club</h2>
</a>
</div>

<div class="burger">
<img src="./assets/images/ham.svg" alt="Hamburger menu" />
</div>

<div class="nav-items">
<ul class="nav-links hide-mobile show-desktop">
<li class="nav-link">
<img src="./assets/images/close.svg" alt="" class="close-btn" />
</li>
<li><a href="./index.html">HOME</a></li>
<li><a href="/blogs">BLOG</a></li>
<li><a href="#">GALLERY</a></li>
<li><a href="./support.html">SUPPORT</a></li>
<li><a href="#">HELP</a></li>
<li><a href="./about.html">ABOUT US</a></li>
</ul>
</div>
</nav>
</header>

<main>
<div class="container">
<h3 class="heading">About Us</h3>
<p>
The need for a technical club which would incorporate the principles
of all engineering branches onto a common platform was felt by the
dynamic students of the college, as a result of which the iter
robotics club was initiated in the year <strong>2007</strong>.
</p>

<p>
​It is an <strong>open club</strong>, co-ordinated by the students,
functioning in the interest of students of the institution wishing to
have a practical application of their knowledge base, gained from the
classrooms.
</p>
<p>
​We at iter robotics club constantly have been working for the
spreading of technical awareness in the field of robotics .
</p>
<p>
​We beileve in creating local hotpots of technical knowledge for the
proper access to technology to the engineering fraternity. We believe
in putting theories into practice in day to day life making process
easier for humans
</p>
<p>
​The worldwide developments in the field of robotics today has
obviously encouraged whooping number of students taking ‘robotics’
into something more than just a hobby.
</p>

<p>
Presently, the IRC has more than <strong>100+</strong> registered
student members from various branches who have shown their excellence
by winning robotics competitions throughout the nation.
</p>
</div>
</main>

<footer class="footer">
<div class="social-icons">
<a href="https://www.facebook.com/IterRoboticsClub"
><img class="fb" src="./assets/images/facebook.svg" alt=""
/></a>
<a href="https://twitter.com/IRC_ITER"
><img src="./assets/images/twitter.svg" alt=""
/></a>
<a href="https://www.youtube.com/channel/UC6g_TZYUIqhkAgU7KS6SB4Q"
><img src="./assets/images/youtube.svg" alt=""
/></a>
<a href="https://www.instagram.com/iter_robotics_club/"
><img src="./assets/images/instagram.svg" alt=""
/></a>
</div>
</footer>

<script src="./assets/js/app.js"></script>
</body>
</html>
Loading