-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afd65d3
commit b79cc79
Showing
28 changed files
with
2,415 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,222 @@ | ||
var express = require('express'), | ||
app = express(), | ||
PORT = 5000 || process.env.port, | ||
bodyParser = require('body-parser'), | ||
mongoose = require('mongoose'), | ||
methodOverride = require('method-override'); | ||
|
||
//Importing passport libraries | ||
var passport = require('passport'), | ||
localStrategy = require('passport-local'), | ||
passportLocalMongoose = require('passport-local-mongoose'); | ||
|
||
app.set("view engine","ejs"); | ||
app.use(express.static("assets")); | ||
app.use(methodOverride("_method")); | ||
app.use(bodyParser.urlencoded({extended:true})); | ||
mongoose.connect("mongodb://localhost/event_db"); | ||
|
||
|
||
//===================== | ||
// MODELS | ||
//===================== | ||
|
||
//User Model | ||
var userSchema = new mongoose.Schema({ | ||
username : String, | ||
password : String, | ||
club_name : String, | ||
club_head_name : String, | ||
contact : Number, | ||
email : String | ||
},{timestamps : true}); | ||
|
||
userSchema.plugin(passportLocalMongoose); | ||
|
||
var User = mongoose.model("User", userSchema); | ||
|
||
//Application model | ||
var appSchema = new mongoose.Schema({ | ||
to : String, | ||
from : String, | ||
subject : String, | ||
purpose : String, | ||
timing : String, | ||
description : String, | ||
applicant : String, | ||
author : { | ||
id : { | ||
type : mongoose.Schema.Types.ObjectId, | ||
rel : "User" | ||
}, | ||
username : String, | ||
email : String | ||
}, | ||
isVerif1 : Boolean, | ||
isVerif2 : Boolean | ||
}, {timestamps : true}); | ||
|
||
var Application = mongoose.model("Application", appSchema); | ||
|
||
//Express-session setup | ||
app.use(require("express-session")({ | ||
secret : "I am AJ", | ||
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()); | ||
|
||
app.use(function(req, res, next){ | ||
res.locals.currentUser = req.user; | ||
next(); | ||
}) | ||
|
||
//===================== | ||
// ROUTES | ||
//===================== | ||
|
||
|
||
//Home route | ||
app.get("/", function(req, res){ | ||
res.render("home"); | ||
}); | ||
|
||
//Application route | ||
app.get("/application", function(req, res){ | ||
User.find({}, function(err, foundUser){ | ||
if(err) | ||
console.log(err); | ||
else | ||
res.render("application", {user : foundUser}); | ||
}); | ||
}); | ||
|
||
app.get("/application/new", function(req, res){ | ||
res.render("newapplication"); | ||
}); | ||
|
||
app.post("/application", function(req, res){ | ||
Application.create({ | ||
to : req.body.to, | ||
from : req.body.from, | ||
subject : req.body.subject, | ||
purpose : req.body.purpose, | ||
timing : req.body.timing, | ||
description : req.body.description, | ||
applicant : req.body.applicant, | ||
author : { | ||
id : req.user._id, | ||
username : req.user.username, | ||
email : req.user.email | ||
}, | ||
isVerif1 : false, | ||
isVerif2 : false | ||
}, function(err, foundApp){ | ||
if(err) | ||
console.log(err); | ||
else | ||
{ | ||
foundApp.save(); | ||
const sgMail = require('@sendgrid/mail'); | ||
sgMail.setApiKey(process.env.SENDGRID_API_KEY); | ||
const msg = { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'Sending with SendGrid is Fun', | ||
text: 'and easy to do anywhere, even with Node.js', | ||
html : '<form action="http://localhost:5000/application/verify1/'+foundApp._id+'"?_method=PUT" method="POST" enctype="multipart/form-data"><button type = "submit">Approve</button></form>' | ||
}; | ||
sgMail.send(msg); | ||
|
||
res.redirect("/"); | ||
} | ||
}); | ||
}); | ||
|
||
app.get("/application/view",function(req,res){ | ||
Application.find({}, function(err, foundApp){ | ||
if(err) | ||
console.log(err); | ||
else | ||
res.render("viewapplication", {applications : foundApp}); | ||
}); | ||
}); | ||
|
||
//Show route | ||
app.get("/application/view/:id", function(req, res){ | ||
Application.findById(req.params.id, function(err, foundApp){ | ||
if(err) | ||
console.log(err); | ||
else | ||
res.render("view", {application : foundApp}); | ||
}); | ||
}); | ||
|
||
app.post("/application/verify1/:id", function(req, res){ | ||
// console.log("PUT Here"); | ||
Application.findById(req.params.id, function(err, foundApp){ | ||
if(err) | ||
{ | ||
console.log(err); | ||
} | ||
else | ||
{ | ||
foundApp.isVerif1 = true; | ||
foundApp.save(); | ||
res.redirect('/'); | ||
} | ||
}) | ||
}); | ||
|
||
// AUTH ROUTES | ||
|
||
//Register Route | ||
app.get("/register", function(req, res){ | ||
res.render("register"); | ||
}); | ||
|
||
app.post("/register", function(req, res){ | ||
var user = new User({username : req.body.username, club_name : req.body.club_name, club_head_name : req.body.club_head_name, contact : req.body.contact, email : req.body.email}); | ||
User.register(user, req.body.password, function(err, newUser){ | ||
if(err) | ||
console.log(err); | ||
else | ||
{ | ||
passport.authenticate("local")(req, res, function(){ | ||
if(err) | ||
console.log(err); | ||
else | ||
res.redirect("/"); | ||
// res.send("success"); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
//Login Route | ||
app.get("/login", function(req, res){ | ||
res.render("login"); | ||
}); | ||
|
||
app.post("/login", passport.authenticate("local",{ | ||
successRedirect : "/", | ||
failureRedirect : "/login" | ||
})); | ||
|
||
//Logout Route | ||
app.get("/logout", function(req, res){ | ||
req.logout(); | ||
res.redirect("/login"); | ||
}) | ||
|
||
app.listen(PORT, function(err){ | ||
if(err) | ||
console.log(err); | ||
else | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
span{ | ||
color: #319719; | ||
} | ||
span2{ | ||
color: #319719; | ||
} | ||
|
||
|
||
|
||
/* Split the screen in half */ | ||
.split { | ||
height: 100%; | ||
width: 50%; | ||
position: fixed; | ||
z-index: 1; | ||
top: 0; | ||
overflow-x: hidden; | ||
padding-top: 20px; | ||
} | ||
|
||
.list-type1{ | ||
background-image: url("list-type1.jpg"); | ||
} | ||
|
||
/* Control the left side */ | ||
.left { | ||
left: 0; | ||
background-color: blue; | ||
background-image: url("/images/photo-1536312819567-fc340bf0ac7c.jpg"); | ||
background-size: cover; | ||
} | ||
|
||
/* Control the right side */ | ||
.right { | ||
right: 0; | ||
background-color: red; | ||
background-image: url("/images/nordwood-themes-483520-unsplash.jpg"); | ||
background-size: cover; | ||
background-position: center; | ||
} | ||
|
||
/* If you want the content centered horizontally and vertically */ | ||
.centered { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
text-align: center; | ||
} | ||
|
||
/* Style the image inside the centered container, if needed */ | ||
.centered img { | ||
width: 150px; | ||
border-radius: 50%; | ||
} | ||
|
||
/*.registerbtn { | ||
background-color: #4CAF50; | ||
color: white; | ||
padding: 16px 20px; | ||
margin: 8px 0; | ||
border: none; | ||
cursor: pointer; | ||
width: 100%; | ||
opacity: 0.9; | ||
} | ||
.registerbtn:hover { | ||
opacity: 1; | ||
}*/ | ||
|
||
.button { | ||
background-color: #4CAF50; | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
margin: 4px 2px; | ||
cursor: pointer; | ||
/*border-radius: 50%;*/ | ||
} | ||
|
||
|
||
.list-type1{ | ||
width:400px; | ||
margin:0 auto; | ||
} | ||
|
||
.list-type1 ol{ | ||
counter-reset: li; | ||
list-style: none; | ||
*list-style: decimal; | ||
font-size: 15px; | ||
font-family: 'Raleway', sans-serif; | ||
padding: 0; | ||
margin-bottom: 4em; | ||
} | ||
.list-type1 ol ol{ | ||
margin: 0 0 0 2em; | ||
} | ||
|
||
.list-type1 a{ | ||
position: relative; | ||
display: block; | ||
padding: .4em .4em .4em 2em; | ||
*padding: .4em; | ||
margin: .5em 0; | ||
background: #93C775; | ||
color: #000; | ||
text-decoration: none; | ||
-moz-border-radius: .3em; | ||
-webkit-border-radius: .3em; | ||
border-radius: 10em; | ||
transition: all .2s ease-in-out; | ||
} | ||
|
||
.list-type1 a:hover{ | ||
background: #d6d4d4; | ||
text-decoration:none; | ||
transform: scale(1.1); | ||
} | ||
|
||
.list-type1 a:before{ | ||
content: counter(li); | ||
counter-increment: li; | ||
position: absolute; | ||
left: -1.3em; | ||
top: 50%; | ||
margin-top: -1.3em; | ||
background:#93C775; | ||
height: 2em; | ||
width: 2em; | ||
line-height: 2em; | ||
border: .3em solid #fff; | ||
text-align: center; | ||
font-weight: bold; | ||
-moz-border-radius: 2em; | ||
-webkit-border-radius: 2em; | ||
border-radius: 2em; | ||
color:#FFF; | ||
} | ||
|
Oops, something went wrong.