Skip to content

Commit

Permalink
flash to session controller
Browse files Browse the repository at this point in the history
  • Loading branch information
pik-nik committed Mar 16, 2023
1 parent 4a13bc7 commit efec3bc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions controllers/session_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ router.get("/", (req, res) => {

router.get("/login", (req, res) => {
const unsuccessfulString = ""
res.render("login", { unsuccessfulString })
res.render("login", { message: req.flash('info') })
})

router.post("/sessions", (req, res) => {
Expand All @@ -20,8 +20,8 @@ router.post("/sessions", (req, res) => {
const sql = `SELECT * FROM users WHERE email = '${email}'`
db.query(sql, (err, dbRes) => {
if (dbRes.rows.length === 0) { // if no user exists
const unsuccessfulString = "Account does not exist with this email"
res.render("login", { unsuccessfulString })
req.flash("info", "Account does not exist with this email")
res.redirect("/login")
return
}
const user = dbRes.rows[0]
Expand All @@ -32,8 +32,8 @@ router.post("/sessions", (req, res) => {
console.log(req.session);
res.redirect(`/users/${user.user_id}`)
} else {
const unsuccessfulString = "Incorrect password, please try again"
res.render("login", { unsuccessfulString })
req.flash("info", "Incorrect password, please try again")
res.redirect("/login")
}
});
})
Expand Down
2 changes: 2 additions & 0 deletions public/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ p {

.already_member a {
color: #fff;
font-size: 20px;
}

.already_member span {
color: #9500ff;
font-family: 'Bebas Neue', cursive;
}

#features ul {
Expand Down
2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
font-family: 'Abel', sans-serif;
margin: 0;
}

Expand Down
6 changes: 5 additions & 1 deletion views/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fortis</title>
<link rel="stylesheet" href="/css/style.css">
<!-- <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@1,900&display=swap" rel="stylesheet"> -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@1,900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Abel&family=Barlow:ital,wght@1,900&family=Bebas+Neue&display=swap" rel="stylesheet">
</head>
<body>

Expand All @@ -29,6 +32,7 @@
<li><a href="/users/workouts"><p class="workouts">My Workouts</p></a></li>
<% if(isLoggedIn()) { %>
<li>
<img src="<%=currentUser.profile_photo%>" alt="">
<p><a href="/users/<%=currentUser.user_id%>"><%=currentUser.username%></a></p>
<form action="/sessions" method="post">
<input type="hidden" name="_method" value="delete"/>
Expand Down
4 changes: 3 additions & 1 deletion views/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<body>
<section class="form_container">
<h2>Login</h2>
<p> <%= unsuccessfulString %> </p>
<% if (message) { %>
<p><%= message %></p>
<% } %>
<form action="/sessions" method="post">
<ul>
<li>
Expand Down

0 comments on commit efec3bc

Please sign in to comment.