Skip to content

Commit

Permalink
Fixed no access to account page
Browse files Browse the repository at this point in the history
Fixed bug where logged in user cannot access account page from Home and Search
  • Loading branch information
ChrisPag committed May 12, 2023
1 parent 9e60c96 commit 4f05428
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ app.get('/',(req, res) => {
const recipeAPI = require('./api/recipe_random');
const async_random = async () => {
const response = await recipeAPI.get_random_recipe(4,['vegetarian','dessert']);

var pageData = {
recipes : response.data.recipes,
userInfo: req.session.username
}
res.render('home',pageData);

}
async_random();
});
Expand All @@ -60,7 +63,7 @@ app.get('/search_result',(req,res) => {
const async_random = async () => {
const response = await recipeAPI.search_recipe(recipe_name,3,sodium,carbs,sugar);
var pageData = {
recipes : response.data.results,
recipes : response.data.results
}
res.render('search',pageData);
}
Expand Down Expand Up @@ -140,16 +143,14 @@ app.get('/update/:id', (req,res) => {

//account page
app.get('/account', async (req,res) => {
let username = req.session.username;
const userInfo = username
const userInfo = req.session.username;
res.render('account', {userInfo});
});

// favourites page
app.get('/favourites', async (req,res) => {
let username = req.session.username;
var pageData = {
userInfo : username,
userInfo : req.session.username,
recipe_title : "Ramen Noodle Coleslaw",
recipe_image : "https://spoonacular.com/recipeImages/Ramen-Noodle-Coleslaw-556177.jpg",
recipe_id : 12345
Expand Down Expand Up @@ -200,6 +201,7 @@ app.get('/search', (req,res) => {
const response = await recipeAPI.get_random_recipe(3,['dessert']);
var pageData = {
recipes : response.data.recipes,
userInfo: req.session.username
}
res.render('search',pageData);
}
Expand Down
Binary file added public/img/home_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/img/logo2.jpg
Binary file not shown.
Binary file added public/img/search_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion views/home.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
<%- include('includes/header') %>
<link rel="stylesheet" type="text/css" href="/css/home.css">
<%- include('includes/nav') %>
<%if(userInfo){%>
<header>
<div class="header-loggedin">
<img id="logo" src="/img/logo2.png">
<nav class="sitelinks">
<a href="/">Home</a>
<a href="/search">Search</a>
</nav>
<nav class="signin">
<ul>
<li>
<a href="/account">Hello, <%= userInfo %></a>
<ul>
<li><a href="/account">My Account</li></a>
<li><a href="/favourites">Favourites</li></a>
<li><a href="/logout">Logout</li></a>
</ul>
</li>
</ul>
</nav>
</div>
<%}else{%>
<%- include('includes/nav')%>
<%}%>

<main class="home">
<section class="hero">
Expand Down
25 changes: 24 additions & 1 deletion views/search.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
<%- include('includes/header') %>
<link rel="stylesheet" type="text/css" href="/css/search.css">
<%- include('includes/nav') %>
<%if(userInfo){%>
<header>
<div class="header-loggedin">
<img id="logo" src="/img/logo2.png">
<nav class="sitelinks">
<a href="/">Home</a>
<a href="/search">Search</a>
</nav>
<nav class="signin">
<ul>
<li>
<a href="/account">Hello, <%= userInfo %></a>
<ul>
<li><a href="/account">My Account</li></a>
<li><a href="/favourites">Favourites</li></a>
<li><a href="/logout">Logout</li></a>
</ul>
</li>
</ul>
</nav>
</div>
<%}else{%>
<%- include('includes/nav')%>
<%}%>
<main>
<section class="searchBar">
<h1>Search Recipes</h1>
Expand Down

0 comments on commit 4f05428

Please sign in to comment.