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

View File

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