Skip to content

Commit

Permalink
Merge pull request #49 from vigneshb27/vigneshb
Browse files Browse the repository at this point in the history
Forgot_password page and Reset_password page have been added along with some other modifications
  • Loading branch information
alphaX86 authored Nov 24, 2021
2 parents 22788b0 + 692fd14 commit f6e6e74
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 62 deletions.
140 changes: 79 additions & 61 deletions app.js
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.");
});
9 changes: 9 additions & 0 deletions contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
- [2020506020 - Bala Subramaniam N](https://github.com/bala418)
- [2020506054 - Monica S](https://github.com/Monica0077)
- [2020506062 - Prabakaran P](https://github.com/Prabakaran2712)
<<<<<<< HEAD
- [2020508048 - Surendar](https://github.com/SurendarSingh)
<<<<<<< HEAD
- [2020506062 - Prabakaran P](https://github.com/Prabakaran2712)
- [2020506107 - Vignesh B](https://github.com/vigneshb27)
=======
>>>>>>> e167f3e230c47b7913da0a8a8e95c6d0f3b341cd
=======
- [2020506066 - Prasath K](https://github.com/Pr454th)
- [2020506070 - Rahul Prasanth D](https://github.com/rahulprasanth487)
- [2020506076 - Sakthivel DS](https://github.com/SakthivelDS)
- [2020506107 - Vignesh B](https://github.com/vigneshb27)
- [2020508048 - Surendar](https://github.com/SurendarSingh)
>>>>>>> 3cd55e756c9f54565b108bf808538ca98882d48e
13 changes: 13 additions & 0 deletions public/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ section#formHolder {
color: #f95959;
}

.forgotpass {
font-size: 13px;
font-weight: 400;
font-family: "Montserrat", sans-serif;
color: #bbbbbb;
text-decoration: underline;
transition: all 0.3s;
}

.forgotpass:hover {
color: #f95959;
}

footer {
text-align: center;
}
Expand Down
125 changes: 125 additions & 0 deletions views/forgot_pass.ejs
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>
3 changes: 2 additions & 1 deletion views/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@

<div class="CTA">
<input type="submit" value="Login" name="log">
<a href="/" class="switch">I'm New</a>
<a href="#" class="switch">I'm New</a>
<a href="/forgotpass" class="forgotpass">Forgot Password</a>
</div>
</form>
</div><!-- End Login Form -->
Expand Down
Loading

0 comments on commit f6e6e74

Please sign in to comment.