From 6d10e0ec625cd8efe653585906a2a3c9429842d6 Mon Sep 17 00:00:00 2001
From: Gabriel Copat <copatg@cardiff.ac.uk>
Date: Tue, 12 Dec 2023 09:57:33 +0000
Subject: [PATCH] Brainstorming work for the next sprint

---
 build.gradle                                    |  1 +
 .../rewards/RewardsRepositoryJDBC.java          |  2 +-
 .../Team5/SmartTowns/users/UserController.java  |  7 +++++++
 src/main/resources/static/css/style.css         |  6 ++++++
 .../templates/allTrails/allTrails.html          |  2 +-
 .../templates/fragments/Templating.html         | 16 ++++++++--------
 src/main/resources/templates/users/logout.html  | 17 +++++++++++++++++
 7 files changed, 41 insertions(+), 10 deletions(-)
 create mode 100644 src/main/resources/templates/users/logout.html

diff --git a/build.gradle b/build.gradle
index 23bab4e1..cb5f573c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -37,6 +37,7 @@ dependencies {
 	testImplementation 'org.springframework.boot:spring-boot-starter-test'
 	implementation 'org.springframework.boot:spring-boot-starter-validation'
 	implementation 'org.springframework.boot:spring-boot-starter-security'
+	implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE'
 	// https://mvnrepository.com/artifact/org.webjars/openlayers
 	implementation group: 'org.webjars', name: 'openlayers', version: '5.2.0'
 }
diff --git a/src/main/java/Team5/SmartTowns/rewards/RewardsRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/rewards/RewardsRepositoryJDBC.java
index e824428f..74c97a5f 100644
--- a/src/main/java/Team5/SmartTowns/rewards/RewardsRepositoryJDBC.java
+++ b/src/main/java/Team5/SmartTowns/rewards/RewardsRepositoryJDBC.java
@@ -59,7 +59,7 @@ public class RewardsRepositoryJDBC implements RewardsRepository {
         /* FINDS ALL STICKERS UNLOCKED BY THE GIVEN USER */
         String sql= "SELECT * FROM stickers LEFT JOIN stickerprogress " +
                 "ON (stickers.id, stickers.packID) = (stickerprogress.stickerID, stickerprogress.packID) " +
-                "WHERE stickerprogress.userID = ? ";
+                "WHERE stickerprogress.username = ? ";
         return jdbc.query(sql, stickerMapper, userID);
     }
 
diff --git a/src/main/java/Team5/SmartTowns/users/UserController.java b/src/main/java/Team5/SmartTowns/users/UserController.java
index b1e96db4..1cc58ecd 100644
--- a/src/main/java/Team5/SmartTowns/users/UserController.java
+++ b/src/main/java/Team5/SmartTowns/users/UserController.java
@@ -6,6 +6,7 @@ import Team5.SmartTowns.rewards.RewardsRepository;
 import Team5.SmartTowns.rewards.Sticker;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.Banner;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.stereotype.Controller;
@@ -34,6 +35,12 @@ public class UserController {
         return mav;
     }
 
+    @GetMapping("/logout")
+    public ModelAndView getLogOutPage(){
+        ModelAndView mav = new ModelAndView("users/logout");
+        return mav;
+    }
+
     @PostMapping("/login/register")
     public ModelAndView registerUser(@Valid @ModelAttribute("user") NewUser user, BindingResult bindingResult, Model model) {
         ModelAndView mav = new ModelAndView("users/login", model.asMap());
diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css
index ca8e9488..934cac13 100644
--- a/src/main/resources/static/css/style.css
+++ b/src/main/resources/static/css/style.css
@@ -52,6 +52,12 @@ body {
     justify-content: center;
     align-content: center;
 }
+.centerAll {
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+}
 
 /*PHONES PORTRAIT*/
 @media only screen
diff --git a/src/main/resources/templates/allTrails/allTrails.html b/src/main/resources/templates/allTrails/allTrails.html
index d29d1ad9..0fefa92c 100644
--- a/src/main/resources/templates/allTrails/allTrails.html
+++ b/src/main/resources/templates/allTrails/allTrails.html
@@ -11,7 +11,7 @@
 <body>
 
 <header th:replace="~{/fragments/Templating.html :: header}"></header>
-
+<div>TEST</div>
 <main>
     <section id="allTrailsBar" class="centerFlex">
         <img class="trailsImages"
diff --git a/src/main/resources/templates/fragments/Templating.html b/src/main/resources/templates/fragments/Templating.html
index 871e541b..e3afc238 100644
--- a/src/main/resources/templates/fragments/Templating.html
+++ b/src/main/resources/templates/fragments/Templating.html
@@ -9,15 +9,15 @@
             <li><a id="homeHead" href="/home">Home</a></li>
             <li>FAQs</li>
             <li>Contact us</li>
+            <li th:if="${#authentication.principal}!=anonymousUser"><a href="/logout">Log Out</a></li>
+            <li th:if="${#authentication.principal}==anonymousUser"><a href="/login">Log In</a></li>
         </ul>
-        <label class="work">Who  we Work with:</label>
-        <select>
-            <ul>
-                <option value="localauthorities">Local Authorities</option>
-                <option value="towns">Towns</option>
-                <option value="businesses">Businesses</option>
-                <option value="consumers">Consumers</option>
-            </ul>
+        <label for="stakeholders" class="work">Who  we Work with:</label>
+        <select id="stakeholders">
+            <option value="localauthorities">Local Authorities</option>
+            <option value="towns">Towns</option>
+            <option value="businesses">Businesses</option>
+            <option value="consumers">Consumers</option>
         </select>
     </nav>
 </header>
diff --git a/src/main/resources/templates/users/logout.html b/src/main/resources/templates/users/logout.html
new file mode 100644
index 00000000..69107ce6
--- /dev/null
+++ b/src/main/resources/templates/users/logout.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Logged Out Successfully</title>
+  <link rel="stylesheet" th:href="@{/css/style.css}">
+  <link rel="stylesheet" th:href="@{/css/login.css}">
+</head>
+<body>
+<main>
+  <div class="container centerAll">
+    <h1>You have successfully logged out</h1>
+  </div>
+</main>
+
+</body>
+</html>
\ No newline at end of file
-- 
GitLab