-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from vigneshb27/vigneshb
Forgot_password page and Reset_password page have been added along with some other modifications
- Loading branch information
Showing
6 changed files
with
381 additions
and
62 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,81 +1,99 @@ | ||
|
||
const express = require('express'), | ||
app = express(), | ||
mongoose = require("mongoose"), | ||
passport = require("passport"), | ||
bodyParser = require("body-parser"), | ||
LocalStrategy = require("passport-local"), | ||
passportLocalMongoose = require("passport-local-mongoose"), | ||
User = require("./database"), | ||
flash = require("connect-flash"); | ||
const express = require("express"), | ||
app = express(), | ||
mongoose = require("mongoose"), | ||
passport = require("passport"), | ||
bodyParser = require("body-parser"), | ||
LocalStrategy = require("passport-local"), | ||
passportLocalMongoose = require("passport-local-mongoose"), | ||
User = require("./database"), | ||
flash = require("connect-flash"); | ||
|
||
app.set("view engine", "ejs"); | ||
app.use(express.static("public")); | ||
|
||
mongoose.connect("mongodb://localhost/pdaregister"); | ||
|
||
app.use(require("express-session")({ | ||
secret:"Any normal Word", | ||
resave: false, | ||
saveUninitialized:false | ||
})); | ||
app.use( | ||
require("express-session")({ | ||
secret: "Any normal Word", | ||
resave: false, | ||
saveUninitialized: false, | ||
}) | ||
); | ||
|
||
passport.serializeUser(User.serializeUser()); | ||
passport.deserializeUser(User.deserializeUser()); | ||
passport.serializeUser(User.serializeUser()); | ||
passport.deserializeUser(User.deserializeUser()); | ||
passport.use(new LocalStrategy(User.authenticate())); | ||
app.set("view engine","ejs"); | ||
app.use(bodyParser.urlencoded( | ||
{ extended:true } | ||
)) | ||
app.set("view engine", "ejs"); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(passport.initialize()); | ||
app.use(passport.session()) | ||
|
||
app.use(passport.session()); | ||
|
||
app.get("/", function(req, res) { | ||
res.render("home"); | ||
app.get("/", function (req, res) { | ||
res.render("home"); | ||
}); | ||
app.get("/login", function(req,res) { | ||
app.get("/login", function (req, res) { | ||
res.render("login"); | ||
}); | ||
app.post("/", function(req, res) { | ||
res.redirect("/"); | ||
app.post("/", function (req, res) { | ||
res.redirect("/"); | ||
}); | ||
app.post("/login",passport.authenticate("local",{ | ||
successRedirect:"/", | ||
failureRedirect:"/login" | ||
}),function (req, res){ | ||
}); | ||
app.post("/register", function(req, res) { | ||
|
||
var flag=0; | ||
var error =new Array(); | ||
var name1=req.body['name']; | ||
var rollnumber=req.body['username']; | ||
var password=req.body['password']; | ||
var cpassword=req.body['cpass']; | ||
var email=req.body['email']; | ||
app.post( | ||
"/login", | ||
passport.authenticate("local", { | ||
successRedirect: "/", | ||
failureRedirect: "/login", | ||
}), | ||
function (req, res) {} | ||
); | ||
app.post("/register", function (req, res) { | ||
var flag = 0; | ||
var error = new Array(); | ||
var name1 = req.body["name"]; | ||
var rollnumber = req.body["username"]; | ||
var password = req.body["password"]; | ||
var cpassword = req.body["cpass"]; | ||
var email = req.body["email"]; | ||
console.log(name1); | ||
User.register(new User({username: req.body.username,email:req.body.email,name: req.body.name}),req.body.password,function(err,user){ | ||
if(err){ | ||
console.log(err); | ||
|
||
res.render("login",{"error":"user already exists"}); | ||
} | ||
passport.authenticate("local")(req,res,function(){ | ||
res.render("login",{"success":"Successfully registered a new user"}); | ||
}) | ||
})}); | ||
app.get("/logout",(req,res)=>{ | ||
req.logout(); | ||
res.redirect('/'); | ||
User.register( | ||
new User({ | ||
username: req.body.username, | ||
email: req.body.email, | ||
name: req.body.name, | ||
}), | ||
req.body.password, | ||
function (err, user) { | ||
if (err) { | ||
console.log(err); | ||
|
||
res.render("login", { error: "user already exists" }); | ||
} | ||
passport.authenticate("local")(req, res, function () { | ||
res.render("login", { success: "Successfully registered a new user" }); | ||
}); | ||
} | ||
); | ||
}); | ||
app.get("/logout", (req, res) => { | ||
req.logout(); | ||
res.redirect("/"); | ||
}); | ||
function isLoggedIn(req,res,next) { | ||
if(req.isAuthenticated()){ | ||
return next(); | ||
|
||
app.get("/forgotpass", (req, res) => { | ||
res.render("forgot_pass"); | ||
}); | ||
|
||
app.get("/resetpass", (req, res) => { | ||
res.render("reset_pass"); | ||
}); | ||
|
||
function isLoggedIn(req, res, next) { | ||
if (req.isAuthenticated()) { | ||
return next(); | ||
} | ||
res.redirect("/login"); | ||
} | ||
|
||
app.listen(3000, function() { | ||
console.log("Server is running on port 3000."); | ||
}); | ||
app.listen(3000, function () { | ||
console.log("Server is running on port 3000."); | ||
}); |
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
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,125 @@ | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<title>Forgot Password</title> | ||
<link rel="stylesheet" href="css/login.css"> | ||
<style> | ||
.box { | ||
margin-top: 160px; | ||
width: 600px; | ||
height: 200px; | ||
color: #443a3a86; | ||
background: #fff; | ||
top: 50%; | ||
left: 50%; | ||
position: relative; | ||
transform: translate(-50%, -50%); | ||
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2); | ||
box-sizing: border-box; | ||
} | ||
h2 { | ||
font-size: 40px; | ||
font-weight: 500; | ||
text-transform: uppercase; | ||
margin-top: 50px; | ||
margin-bottom: 0; | ||
text-align: center; | ||
} | ||
p { | ||
font-size: 15px; | ||
font-weight: 300; | ||
text-transform: uppercase; | ||
letter-spacing: 2px; | ||
white-space: 4px; | ||
font-family: "Raleway", sans-serif; | ||
text-align: center; | ||
} | ||
.form form input:not([type="submit"]) { | ||
border-bottom: 1px solid rgb(226, 221, 221); | ||
} | ||
#goback { | ||
color: #443a3a86; | ||
} | ||
#goback:hover{ | ||
color: #f95959; | ||
cursor: pointer; | ||
} | ||
#submit:hover{ | ||
cursor: pointer; | ||
} | ||
@media (max-width: 480px) { | ||
.wrap { | ||
width: 400px; | ||
overflow: hidden; | ||
} | ||
.box { | ||
position: fixed; | ||
margin-top: 80px; | ||
width: 80%; | ||
} | ||
#highlight { | ||
margin: 10px; | ||
} | ||
} | ||
@media (min-width: 768px) { | ||
.wrap { | ||
width: 100%; | ||
overflow: hidden; | ||
} | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="wrap"> | ||
<div class="col-sm-6 form"> | ||
|
||
<div id="highlight"> | ||
<h2>FORGOT PASSWORD</h2> | ||
<p>Enter your registered email to reset your password.</p> | ||
|
||
</div> | ||
|
||
<div class="box"> | ||
<form class="signup-form" action="/" method="post" onsubmit="sent_mail()"> | ||
|
||
|
||
<div class="form-group"> | ||
<label for="email">Email Address</label> | ||
<input type="email" name="email" id="email" class="email" required> | ||
<span class="error"></span> | ||
</div> | ||
<div class="CTA"> | ||
<input type="submit" value="Proceed" id="submit" name="proceed"> | ||
<a href="/login" class="switch" id="goback">Back to login</a> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
function sent_mail() | ||
{ | ||
alert("A link to reset your password has been sent to your email"); | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
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
Oops, something went wrong.