Skip to content

Commit

Permalink
app
Browse files Browse the repository at this point in the history
  • Loading branch information
Deep52 committed Apr 22, 2022
1 parent b8307b0 commit b29608e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 10 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ app.set("view engine", "ejs");
// set root page to index.ejs and pass in the title of the webpage
app.get("/", function(req, res) {
let title = "Blog Website";
const username = '';
res.render("index", { title: title });
});

Expand Down Expand Up @@ -114,9 +115,14 @@ app.post('/login', async(req, res, next) => {
if (results_c.rowCount == '1') {

sess = req.session;
sess.id = req.session.id;

res.render('write_blog', { login_ss: 'User successfully Login ' + sess.id });
id = req.session.id;
// console.log(req.cookies);
//username = id;
//console.log(useusernamername);
res.cookie('username', id, { maxAge: 900000, httpOnly: true });
// res.cookie('pardeep', 'kjghjhv', { maxAge: 900000, httpOnly: true });
// res.cookie("username", username);
res.render('write_blog', { login_ss: 'User successfully Login ' + res.cookie.username });


} else {
Expand All @@ -143,6 +149,7 @@ app.get('/logout', (req, res) => {
if (err) {
return console.log(err);
}
res.clearCookie("username");
res.render('Login');
//res.redirect('/');
});
Expand Down
10 changes: 7 additions & 3 deletions views/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
<a href="./">Home</a> |
<a href="./register" class="rl">| Register</a> |

<% if(typeof login_ss == 'undefined' || login_ss == null ){ %>


<%if(locals.username ){%>
<a href="/login">Login</a>
<% } else{ %>
<%=locals.username%>
<a href="/logout">Logout</a>
<a href="/logout">Logout</a>
<% } %>
<% } %>
</nav>
</header>

0 comments on commit b29608e

Please sign in to comment.