implement login + header

This commit is contained in:
CodeSteak 2020-01-25 22:13:26 +01:00
parent 5cd4f87096
commit 26d05eace5
5 changed files with 230 additions and 191 deletions

View File

@ -0,0 +1,17 @@
package org.hso.ecommerce.app;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.hso.ecommerce.components.LoginIntercepter;
@Configuration
public class Config implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginIntercepter());
}
}

View File

@ -18,13 +18,6 @@ import java.util.UUID;
@Controller @Controller
public class RequestController { public class RequestController {
private final CustomerRepository customerRepo;
@Autowired
public RequestController(CustomerRepository customerRepo) {
this.customerRepo = customerRepo;
}
@GetMapping("/") @GetMapping("/")
public String home() { public String home() {
return "redirect:/shop/"; return "redirect:/shop/";
@ -36,7 +29,14 @@ public class RequestController {
} }
@PostMapping("/login") @PostMapping("/login")
public String loginPost() { public String loginPost(HttpServletResponse response) {
response.addCookie(new Cookie("login", "true"));
return "redirect:/";
}
@PostMapping("/logout")
public String logoutPost(HttpServletResponse response) {
response.addCookie(new Cookie("login", "false"));
return "redirect:/"; return "redirect:/";
} }
@ -81,7 +81,7 @@ public class RequestController {
@GetMapping("/user/") @GetMapping("/user/")
public String user() { public String user() {
return "/user/index"; return "redirect:/user/settings";
} }
@GetMapping("/user/settings") @GetMapping("/user/settings")

View File

@ -0,0 +1,39 @@
package org.hso.ecommerce.components;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LoginIntercepter implements HandlerInterceptor {
@Override
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie c : cookies) {
if (c.getName().equals("login")) {
request.setAttribute("customer", c.getValue().equals("true"));
}
}
}
return true;
}
@Override
public void postHandle(
HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception exception) throws Exception {}
}

View File

@ -1,9 +1,45 @@
@import "fonts.css"; @import "fonts.css";
.dropdown {
width: 15rem;
display: block;
}
.dropdown-content {
display: none;
position: absolute;
}
.dropdown .dropdown-button {
display: block;
width: 15rem;
margin-top: 0px;
margin-bottom: 0px;
}
.dropdown:hover .dropdown-content {
}
.dropdown:hover .dropdown-button {
display: inline-block;
background-color: var(--root-c-black);
width: 15rem;
margin: 0px;
}
.dropdown:hover .dropdown-content {
display: flex;
flex-direction: column;
align-items: stretch;
}
.dropdown:hover .dropdown-content>* {
margin: 0px;
min-width: 15rem;
}
:root { :root {
font-family: "Fira Sans"; font-family: "Fira Sans";
line-height: 1.15; line-height: 1.15;
--u5: calc(1em * 1.5 * 1.5 * 1.5 * 1.5 * 1.5); --u5: calc(1em * 1.5 * 1.5 * 1.5 * 1.5 * 1.5);
--u4: calc(1em * 1.5 * 1.5 * 1.5 * 1.5); --u4: calc(1em * 1.5 * 1.5 * 1.5 * 1.5);
--u3: calc(1em * 1.5 * 1.5 * 1.5); --u3: calc(1em * 1.5 * 1.5 * 1.5);
@ -14,46 +50,32 @@
--u-2: calc(1em * 0.666 * 0.666); --u-2: calc(1em * 0.666 * 0.666);
--u-3: calc(1em * 0.666 * 0.666 * 0.666); --u-3: calc(1em * 0.666 * 0.666 * 0.666);
--u-4: calc(1em * 0.666 * 0.666 * 0.666 * 0.666); --u-4: calc(1em * 0.666 * 0.666 * 0.666 * 0.666);
--root-c-base: #ecf0f1; --root-c-base: #ecf0f1;
--root-c-base-highlight: #FFF; --root-c-base-highlight: #FFF;
--root-c-primary: #1abc9c; --root-c-primary: #1abc9c;
--root-c-primary-highlight: #16a085; --root-c-primary-highlight: #16a085;
--root-c-secondary: #9b59b6; --root-c-secondary: #9b59b6;
--root-c-secondary-highlight: #8e44ad; --root-c-secondary-highlight: #8e44ad;
--root-c-black: #2c3e50; --root-c-black: #2c3e50;
--root-c-black-highlight: #34495e; --root-c-black-highlight: #34495e;
--c-base: var(--root-c-base); --c-base: var(--root-c-base);
--c-base-highlight: var(--root-c-base-highlight); --c-base-highlight: var(--root-c-base-highlight);
--c-primary: var(--root-c-primary); --c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-primary-highlight); --c-primary-highlight: var(--root-c-primary-highlight);
--c-secondary: var(--root-c-secondary); --c-secondary: var(--root-c-secondary);
--c-secondary-highlight: var(--root-c-secondary-highlight); --c-secondary-highlight: var(--root-c-secondary-highlight);
--c-black: var(--root-c-black); --c-black: var(--root-c-black);
--c-black-highlight: var(--root-c-black-highlight); --c-black-highlight: var(--root-c-black-highlight);
--c-error: #c0392b; --c-error: #c0392b;
} }
.primary { .primary {
--c-base: var(--root-c-base); --c-base: var(--root-c-base);
--c-base-highlight: var(--root-c-base-highlight); --c-base-highlight: var(--root-c-base-highlight);
--c-primary: var(--root-c-primary); --c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-primary-highlight); --c-primary-highlight: var(--root-c-primary-highlight);
--c-secondary: var(--c-secondary); --c-secondary: var(--c-secondary);
--c-secondary-highlight: var(--root-c-secondary-highlight); --c-secondary-highlight: var(--root-c-secondary-highlight);
--c-black: var(--root-c-black); --c-black: var(--root-c-black);
--c-black-highlight: var(--root-c-black-highlight); --c-black-highlight: var(--root-c-black-highlight);
} }
@ -61,13 +83,32 @@
.secondary { .secondary {
--c-base: var(--root-c-base); --c-base: var(--root-c-base);
--c-base-highlight: var(--root-c-base-highlight); --c-base-highlight: var(--root-c-base-highlight);
--c-primary: var(--root-c-secondary); --c-primary: var(--root-c-secondary);
--c-primary-highlight: var(--root-c-secondary-highlight); --c-primary-highlight: var(--root-c-secondary-highlight);
--c-secondary: var(--root-c-primary); --c-secondary: var(--root-c-primary);
--c-secondary-highlight: var(--root-c-primary-highlight); --c-secondary-highlight: var(--root-c-primary-highlight);
--c-black: var(--root-c-black);
--c-black-highlight: var(--root-c-black-highlight);
}
.black {
--c-base: var(--root-c-base);
--c-base-highlight: var(--root-c-base-highlight);
--c-primary: var(--root-c-black);
--c-primary-highlight: var(--root-c-black-highlight);
--c-secondary: var(--root-c-primary);
--c-secondary-highlight: var(--root-c-primary-highlight);
--c-black: var(--root-c-primary);
--c-black-highlight: var(--root-c-primary-highlight);
}
.black-as-highlight {
--c-base: var(--root-c-base);
--c-base-highlight: var(--root-c-black-highlight);
--c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-black-highlight);
--c-secondary: var(--root-c-secondary);
--c-secondary-highlight: var(--root-c-black-highlight);
--c-black: var(--root-c-black); --c-black: var(--root-c-black);
--c-black-highlight: var(--root-c-black-highlight); --c-black-highlight: var(--root-c-black-highlight);
} }
@ -75,13 +116,10 @@
.inverted { .inverted {
--c-base: var(--root-c-black); --c-base: var(--root-c-black);
--c-base-highlight: var(--root-c-black-highlight); --c-base-highlight: var(--root-c-black-highlight);
--c-primary: var(--root-c-primary); --c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-primary-highlight); --c-primary-highlight: var(--root-c-primary-highlight);
--c-secondary: var(--c-secondary); --c-secondary: var(--c-secondary);
--c-secondary-highlight: var(--root-c-secondary-highlight); --c-secondary-highlight: var(--root-c-secondary-highlight);
--c-black: var(--root-c-base); --c-black: var(--root-c-base);
--c-black-highlight: var(--root-c-base-highlight); --c-black-highlight: var(--root-c-base-highlight);
} }
@ -126,20 +164,14 @@
.highlight { .highlight {
--c-base: var(--root-c-black); --c-base: var(--root-c-black);
--c-base-highlight: var(--root-c-black-highlight); --c-base-highlight: var(--root-c-black-highlight);
--c-primary: var(--root-c-primary); --c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-primary-highlight); --c-primary-highlight: var(--root-c-primary-highlight);
--c-secondary: var(--c-secondary); --c-secondary: var(--c-secondary);
--c-secondary-highlight: var(--root-c-secondary-highlight); --c-secondary-highlight: var(--root-c-secondary-highlight);
--c-black: var(--root-c-base); --c-black: var(--root-c-base);
--c-black-highlight: var(--root-c-base-highlight); --c-black-highlight: var(--root-c-base-highlight);
} }
.huge { .huge {
--u5: calc(3.375rem * 1.5 * 1.5 * 1.5 * 1.5 * 1.5); --u5: calc(3.375rem * 1.5 * 1.5 * 1.5 * 1.5 * 1.5);
--u4: calc(3.375rem * 1.5 * 1.5 * 1.5 * 1.5); --u4: calc(3.375rem * 1.5 * 1.5 * 1.5 * 1.5);
@ -166,8 +198,6 @@
--u-4: calc(0.666em * 0.666 * 0.666 * 0.666 * 0.666); --u-4: calc(0.666em * 0.666 * 0.666 * 0.666 * 0.666);
} }
* { * {
margin: 0em; margin: 0em;
padding: 0em; padding: 0em;
@ -185,7 +215,6 @@ main {
min-height: 100%; min-height: 100%;
} }
h1, h2, h3, h4, h5 { h1, h2, h3, h4, h5 {
font-family: "Fira Mono"; font-family: "Fira Mono";
padding-top: var(--u0); padding-top: var(--u0);
@ -199,7 +228,7 @@ a {
} }
a:visited { a:visited {
color: inherit; color: none;
} }
a.section { a.section {
@ -228,6 +257,10 @@ img {
object-fit: cover; object-fit: cover;
} }
img.icon {
height: 2rem;
}
li { li {
list-style-type: none; list-style-type: none;
} }
@ -273,8 +306,6 @@ table.key-value td {
text-align: left; text-align: left;
} }
img.xs { img.xs {
width: var(--u2); width: var(--u2);
} }
@ -283,7 +314,6 @@ img.s {
width: var(--u4); width: var(--u4);
} }
img.m { img.m {
width: var(--u8); width: var(--u8);
} }
@ -291,10 +321,7 @@ img.m {
/* /*
* NAV * NAV
*/ */
nav {}
nav {
}
nav h1 { nav h1 {
font-size: var(--u0); font-size: var(--u0);
@ -312,7 +339,7 @@ nav li li {
nav li a { nav li a {
padding: var(--u0); padding: var(--u0);
transition: all 0.1s ease-out; transition: background-color 0.1s ease-out;
} }
nav li a:hover, nav li a:hover,
@ -321,10 +348,10 @@ nav li a.selected {
background-color: var(--c-primary); background-color: var(--c-primary);
color: var(--c-base); color: var(--c-base);
} }
/* /*
* FOOTER * FOOTER
*/ */
footer { footer {
padding-top: var(--u3); padding-top: var(--u3);
padding-bottom: var(--u1); padding-bottom: var(--u1);
@ -337,20 +364,15 @@ textarea,
input[list], input[list],
input[type="text"], input[type="text"],
input[type="password"] { input[type="password"] {
background-color: var(--c-base); background-color: var(--c-base);
font-size: var(--u0); font-size: var(--u0);
border: none; border: none;
/*border-radius: var(--u-2);*/ /*border-radius: var(--u-2);*/
margin-top: var(--u0); margin-top: var(--u0);
margin-bottom: var(--u0); margin-bottom: var(--u0);
padding: var(--u0); padding: var(--u0);
font-size: var(--u0); font-size: var(--u0);
color: var(--c-black); color: var(--c-black);
background-color: var(--c-base-highlight); background-color: var(--c-base-highlight);
box-shadow: var(--s-0-secondary); box-shadow: var(--s-0-secondary);
} }
@ -358,6 +380,7 @@ input[type="password"] {
textarea { textarea {
font-family: "Fira Mono"; font-family: "Fira Mono";
} }
/* /*
input[type="text"]:invalid, input[type="text"]:invalid,
input[type="password"]:invalid { input[type="password"]:invalid {
@ -377,32 +400,20 @@ button, .button {
font-weight: bold; font-weight: bold;
text-decoration: none; text-decoration: none;
text-align: center; text-align: center;
background-color: var(--c-primary); background-color: var(--c-primary);
color: var(--c-base); color: var(--c-base);
border: none; border: none;
/*border-radius: var(--u-2);*/ /*border-radius: var(--u-2);*/
margin-bottom: var(--u0); margin-bottom: var(--u0);
margin-top: var(--u0); margin-top: var(--u0);
padding: var(--u0); padding: var(--u0);
min-width: 10em; min-width: 10em;
font-family: "Fira Mono"; font-family: "Fira Mono";
text-transform: uppercase; text-transform: uppercase;
font-size: var(--u0); font-size: var(--u0);
/* box-shadow: var(--s-0-secondary); */ /* box-shadow: var(--s-0-secondary); */
} }
nav button.bg-none,
nav .button.bg-none {
background-color: transparent;
}
button:active, .button:active { button:active, .button:active {
background-color: var(--c-primary-highlight); background-color: var(--c-primary-highlight);
} }
@ -412,7 +423,7 @@ input[type="password"],
input[list], input[list],
button, button,
.button { .button {
transition: all 0.1s ease-out; transition: background-color 0.1s ease-out;
} }
label { label {
@ -443,7 +454,6 @@ fieldset label {
/* /*
* HERO * HERO
*/ */
.hero { .hero {
background-color: var(--c-primary); background-color: var(--c-primary);
color: var(--c-base); color: var(--c-base);
@ -454,6 +464,11 @@ fieldset label {
--c-primary-highlight: var(--root-c-primary); --c-primary-highlight: var(--root-c-primary);
} }
.header.hero>* {
--c-primary: var(--root-c-primary);
--c-primary-highlight: var(--root-c-primary-highlight);
}
.hero-black { .hero-black {
background-color: var(--c-black); background-color: var(--c-black);
color: var(--c-base); color: var(--c-base);
@ -470,12 +485,10 @@ fieldset label {
/* /*
* LAYOUT * LAYOUT
*/ */
.content-width { .content-width {
max-width: 80rem; max-width: 80rem;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
padding-left: var(--u0); padding-left: var(--u0);
padding-right: var(--u0); padding-right: var(--u0);
} }
@ -490,16 +503,17 @@ fieldset label {
justify-content: stretch; justify-content: stretch;
flex-wrap: wrap; flex-wrap: wrap;
} }
.flowflex>* { .flowflex>* {
padding: var(--u0); padding: var(--u0);
flex: 1; flex: 1;
} }
.flowflex>*.spacer { .flowflex>*.spacer {
padding-top: 0px; padding-top: 0px;
padding-bottom: 0px; padding-bottom: 0px;
} }
.detailflex { .detailflex {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -532,7 +546,6 @@ fieldset label {
flex: 1; flex: 1;
} }
.detailflex>.col-2 { .detailflex>.col-2 {
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
@ -547,7 +560,6 @@ fieldset label {
padding: var(--u0); padding: var(--u0);
} }
.detailgrid { .detailgrid {
display: grid; display: grid;
grid-auto-flow: dense; grid-auto-flow: dense;
@ -576,7 +588,6 @@ fieldset label {
margin-right: auto; margin-right: auto;
} }
.detailgrid>.s { .detailgrid>.s {
grid-column: span 1; grid-column: span 1;
} }
@ -594,7 +605,6 @@ fieldset label {
height: 0px; height: 0px;
} }
.bar-flex { .bar-flex {
display: flex; display: flex;
align-items: center; align-items: center;
@ -682,10 +692,8 @@ fieldset label {
.grid.s>.spacer { .grid.s>.spacer {
box-shadow: none; box-shadow: none;
margin: calc(var(--u0) * 2); margin: calc(var(--u0) * 2);
padding: 0px; padding: 0px;
width: 10rem; width: 10rem;
max-width: 10rem; max-width: 10rem;
min-width: 7.5rem; min-width: 7.5rem;
@ -697,13 +705,10 @@ fieldset label {
min-width: 7.5rem; min-width: 7.5rem;
} }
.grid.m>.spacer { .grid.m>.spacer {
box-shadow: none; box-shadow: none;
margin: calc(var(--u0) * 2); margin: calc(var(--u0) * 2);
padding: 0px; padding: 0px;
width: 20rem; width: 20rem;
max-width: 20rem; max-width: 20rem;
min-width: 15rem; min-width: 15rem;
@ -719,10 +724,8 @@ fieldset label {
.grid.l>.spacer { .grid.l>.spacer {
box-shadow: none; box-shadow: none;
margin: calc(var(--u0) * 2); margin: calc(var(--u0) * 2);
padding: 0px; padding: 0px;
width: 40rem; width: 40rem;
max-width: 40rem; max-width: 40rem;
min-width: 15rem; min-width: 15rem;
@ -738,10 +741,8 @@ fieldset label {
.grid.xl>.spacer { .grid.xl>.spacer {
box-shadow: none; box-shadow: none;
margin: calc(var(--u0) * 2); margin: calc(var(--u0) * 2);
padding: 0px; padding: 0px;
width: 80rem; width: 80rem;
max-width: 80rem; max-width: 80rem;
min-width: 30rem; min-width: 30rem;
@ -755,8 +756,6 @@ fieldset label {
min-width: 20rem; min-width: 20rem;
} }
.vertical-spacer.s { .vertical-spacer.s {
min-height: 10rem; min-height: 10rem;
} }
@ -784,12 +783,10 @@ fieldset label {
/* /*
* Impov * Impov
*/ */
.input-icon { .input-icon {
/* box-shadow: var(--s-0-secondary); */ /* box-shadow: var(--s-0-secondary); */
display: flex; display: flex;
padding: 0px; padding: 0px;
/*border-radius: var(--u0);*/ /*border-radius: var(--u0);*/
} }
@ -803,20 +800,15 @@ fieldset label {
.input-icon>button { .input-icon>button {
margin: 0px; margin: 0px;
border-top-left-radius: 0px; border-top-left-radius: 0px;
border-bottom-left-radius: 0px; border-bottom-left-radius: 0px;
box-shadow: none; box-shadow: none;
} }
/* /*
* CONTENT * CONTENT
*/ */
.notification {}
.notification {
}
.notification:hover { .notification:hover {
background-color: var(--c-base-highlight); background-color: var(--c-base-highlight);
@ -831,7 +823,6 @@ fieldset label {
--c-primary-highlight: var(--root-c-primary); --c-primary-highlight: var(--root-c-primary);
} }
.notification.unread:hover { .notification.unread:hover {
background-color: var(--c-primary); background-color: var(--c-primary);
} }
@ -867,6 +858,7 @@ fieldset label {
.no-padding { .no-padding {
padding: 0px; padding: 0px;
} }
.no-margin { .no-margin {
margin: 0px; margin: 0px;
} }

View File

@ -5,33 +5,24 @@
<title>eCommerce</title> <title>eCommerce</title>
</head> </head>
<body> <body>
<nav class='hero' th:fragment="header"> <nav class='hero header' th:fragment="header">
<div class='content-width bar-flex'> <div class='content-width bar-flex'>
<a class="button bg-none" href="/">Project eCommerce</a> <a class="button" href="/">Project eCommerce</a>
<a class="button bg-none" href="/">Angebote</a>
<form class='spacer input-icon secondary' th:action="@{/shop/search}" method="GET"> <form class='spacer input-icon secondary' th:action="@{/shop/search}" method="GET">
<input type="text" placeholder="Nach Produkten suchen..."/> <input type="text" placeholder="Nach Produkten suchen..."/>
<button>Finden</button> <button>Finden</button>
</form> </form>
<a th:unless="${customer}" class="button bg-none" th:href="@{/login}">Login</a> <a th:unless="${customer}" class="button" th:href="@{/login}">Login</a>
<div class="notifications" th:if="${customer}" style="display: none;"> <div th:if="${customer}" class="dropdown">
<input id="messages" type="checkbox"></input> <a class="dropdown-button button">Mein Konto</a>
<label for="messages" class="button"> <div class="dropdown-content">
<img th:src="@{/img/bell.svg}" width="25" height="28" alt="Nachrichten"/> <a class="black button" th:href="@{/user/notifications/}">Benachrichtigungen</a>
</label> <a class="black button" th:href="@{/user/}">Einstellungen</a>
<ul class="listbox"> <a class="black button" th:href="@{/user/orders/}">Meine Bestellungen</a>
<li class="unread"> <form th:if="${customer}" method="post" th:action="@{/logout}" class="no-margin"><button class="bg-black no-margin full-width">Abmelden</button></form>
Ihre Bestellung kommt voraussichtlich am Donnerstag, den 20.08.2020
</li>
<li class="unread">
Ihre Rücksendung ist bei uns eingegangen.
</li>
<li>
Ihre Bestellung wurde versandt.
</li>
</ul>
</div> </div>
<a th:if="${customer}" class="button" th:href="@{/logout}">Abmelden</a> </div>
<a th:if="${customer}" class="button" th:href="@{/shop/checkout}">Warenkorb</a>
</div> </div>
</nav> </nav>
</body> </body>