From 0f7d248d40a6eb8bde08469d2656d310a91c17d7 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 12 Jun 2020 23:31:57 +0200 Subject: [PATCH 1/3] add radio BTNs to register --- .../controller/RegisterController.java | 4 +- .../main/resources/templates/register.html | 140 +++++++++--------- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index 19f81b7..efd6970 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java @@ -31,8 +31,8 @@ public class RegisterController { @RequestParam("salutation") String salutation, @RequestParam("name") String name, @RequestParam("address") String address, - @RequestParam("type") String type, - @RequestParam("ad") String ad, + @RequestParam("type") String type, //TODO store + @RequestParam("ad") String ad, //TODO store HttpSession session ) { diff --git a/prototype/src/main/resources/templates/register.html b/prototype/src/main/resources/templates/register.html index fccb016..a2ef401 100644 --- a/prototype/src/main/resources/templates/register.html +++ b/prototype/src/main/resources/templates/register.html @@ -1,78 +1,84 @@ - - - - - - Neuen Account erstellen - - - - - - - -
-
-
-

Neuen Account erstellen

-
-
-

Login Daten

-
-
- - -
- -
- - -
- -
- - -
- -
-

Rechungs- und Lieferinformation

-
- -
+ + + + Neuen Account erstellen + + + + + +
+
- - - - +

Neuen Account erstellen

- - +

Login Daten

-
- -
+
+ + +
+
+ + +
+
+ + +
+
+

Rechungs- und Lieferinformation

+
+
+
+ + + + +
+
+ + +
+
+
-
-
+ placeholder="Optional: Zusatz Optional: Unternehmen Straße Hausnummer Postleitzeit Ort Land"> +
+
+ +
+ +
+
+
+

Werbung

+
+
+
+ +
+ +
+
+
+
- Unsere AGBs finden sie hier. + Unsere AGBs finden sie hier. -
- - -
- - - - + + + + + + \ No newline at end of file -- 2.47.1 From a41889b2cbe1cd9e172e8168fe81c386c4e953bd Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 12 Jun 2020 23:48:28 +0200 Subject: [PATCH 2/3] login in extern loginController, RequestController cleanup, login right after register --- .../hso/ecommerce/app/RequestController.java | 83 ++------------ .../ecommerce/controller/LoginController.java | 63 ++++++++++- .../controller/RegisterController.java | 105 +++++++++--------- 3 files changed, 123 insertions(+), 128 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java index 3039bb9..406e283 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java @@ -1,17 +1,7 @@ package org.hso.ecommerce.app; -import org.hso.ecommerce.entities.user.User; -import org.hso.ecommerce.repos.user.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.util.Optional; /** * TODO clean up this class @@ -19,70 +9,13 @@ import java.util.Optional; @Controller public class RequestController { - @Autowired - private final UserRepository userRepository = null; - - static int notSoRandom = 0; - - @GetMapping("/login") - public String login() { - return "login"; - } - - @PostMapping("/login") - public String loginPost( - HttpServletRequest request, - HttpServletResponse response, - @RequestParam("username") String username, - @RequestParam("password") String password, - HttpSession session - ) { - String gto = (String) session.getAttribute("afterLogin"); - - Optional user = userRepository.findByEmail(username); - if (!user.isPresent()) { - request.setAttribute("error", "Email Adresse falsch."); - response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); - return "login"; - } - - if (!user.get().validatePassword(password)) { - request.setAttribute("error", "Passwort falsch."); - response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); - return "login"; - } - - if (!user.get().isActive) { - request.setAttribute("error", "User ist deaktiviert."); - response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); - return "login"; - } - - session.setAttribute("userId", user.get().getId()); - - if (gto != null && gto.startsWith("/")) { - return "redirect:" + gto; - } else { - return "redirect:/"; - } - } - - @PostMapping("/logout") - public String logoutPost(HttpServletResponse response, - HttpSession session - ) { - session.removeAttribute("userId"); - return "redirect:/"; - } - - @GetMapping("/intern/customerOrders/") - public String internCustomerOrder() { - return "intern/customerOrders/index"; - } - - @GetMapping("/intern/customerOrders/{id}") - public String internCustomerOrdersId() { - return "intern/customerOrders/id"; - } + @GetMapping("/intern/customerOrders/") + public String internCustomerOrder() { + return "intern/customerOrders/index"; + } + @GetMapping("/intern/customerOrders/{id}") + public String internCustomerOrdersId() { + return "intern/customerOrders/id"; + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java index 5f4ebad..0138257 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java @@ -1,8 +1,69 @@ package org.hso.ecommerce.controller; +import java.util.Optional; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.hso.ecommerce.entities.user.User; +import org.hso.ecommerce.repos.user.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; @Controller -//@RequestMapping("...") +@RequestMapping("/") public class LoginController { + + @Autowired + private final UserRepository userRepository = null; + + @GetMapping("login") + public String login() { + return "login"; + } + + @PostMapping("login") + public String loginPost(HttpServletRequest request, HttpServletResponse response, + @RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) { + + String gto = (String) session.getAttribute("afterLogin"); + + Optional user = userRepository.findByEmail(username); + if (!user.isPresent()) { + request.setAttribute("error", "Email Adresse falsch."); + response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); + return "login"; + } + + if (!user.get().validatePassword(password)) { + request.setAttribute("error", "Passwort falsch."); + response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); + return "login"; + } + + if (!user.get().isActive) { + request.setAttribute("error", "User ist deaktiviert."); + response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); + return "login"; + } + + session.setAttribute("userId", user.get().getId()); + + if (gto != null && gto.startsWith("/")) { + return "redirect:" + gto; + } else { + return "redirect:/"; + } + } + + @PostMapping("logout") + public String logoutPost(HttpServletResponse response, HttpSession session) { + session.removeAttribute("userId"); + return "redirect:/"; + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index efd6970..b58099d 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java @@ -16,66 +16,67 @@ import javax.servlet.http.HttpSession; import java.util.Optional; @Controller -public class RegisterController { +public class RegisterController { - @Autowired - private final UserRepository userRepository = null; + @Autowired + private final UserRepository userRepository = null; - @PostMapping("/register") - public String registerPost( - HttpServletRequest request, - HttpServletResponse response, - @RequestParam("username") String username, - @RequestParam("password") String password, - @RequestParam("password2") String password2, - @RequestParam("salutation") String salutation, - @RequestParam("name") String name, - @RequestParam("address") String address, - @RequestParam("type") String type, //TODO store - @RequestParam("ad") String ad, //TODO store - HttpSession session - ) - { - Optional user = userRepository.findByEmail(username); - if (user.isPresent()) { - request.setAttribute("error", "Email Adresse existiert bereits!"); - response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); - return "register"; - } + @PostMapping("/register") + public String registerPost(HttpServletRequest request, HttpServletResponse response, + @RequestParam("username") String username, @RequestParam("password") String password, + @RequestParam("password2") String password2, @RequestParam("salutation") String salutation, + @RequestParam("name") String name, @RequestParam("address") String address, + @RequestParam("type") String type, // TODO store + @RequestParam("ad") String ad, // TODO store + HttpSession session) { + Optional user = userRepository.findByEmail(username); + if (user.isPresent()) { + request.setAttribute("error", "Email Adresse existiert bereits!"); + response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); + return "register"; + } - if (!password.equals(password2)){ - request.setAttribute("error", "Passwörter sind nicht gleich"); - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - return "register"; - } + if (!password.equals(password2)) { + request.setAttribute("error", "Passwörter sind nicht gleich"); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return "register"; + } - //set values for new user - User newUser = new User(); - newUser.email = username; - newUser.setPassword(password); - newUser.email = username; - newUser.isEmployee = false; - newUser.salutation = salutation; - newUser.defaultPayment = PaymentMethod.fromCreditCardNumber(""); + // set values for new user + User newUser = new User(); + newUser.email = username; + newUser.setPassword(password); + newUser.email = username; + newUser.isEmployee = false; + newUser.salutation = salutation; + newUser.defaultPayment = PaymentMethod.fromCreditCardNumber(""); - newUser.isActive = true; - newUser.created = new java.sql.Timestamp(System.currentTimeMillis()); + newUser.isActive = true; + newUser.created = new java.sql.Timestamp(System.currentTimeMillis()); - Address newAddress = new Address(); - newAddress.name = name; - newAddress.addressString = address; - newUser.defaultDeliveryAddress = newAddress; + Address newAddress = new Address(); + newAddress.name = name; + newAddress.addressString = address; + newUser.defaultDeliveryAddress = newAddress; - userRepository.save(newUser); // save newUser + userRepository.save(newUser); // save newUser - user = userRepository.findByEmail(username); - session.setAttribute("userId", user.get().getId()); + user = userRepository.findByEmail(username); + session.setAttribute("userId", user.get().getId()); - return "redirect:/"; - } + String gto = (String) session.getAttribute("afterLogin"); - @GetMapping("/register") - public String register() { - return "register"; - } + //login after register + if (gto != null && gto.startsWith("/")) { + return "redirect:" + gto; + } else { + return "redirect:/"; + } + + } + + @GetMapping("/register") + public String register() { + return "register"; + } } -- 2.47.1 From e0e853a57568337752a7bb22e196212da77696c9 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 13 Jun 2020 10:41:59 +0200 Subject: [PATCH 3/3] fixes from PR review --- .../org/hso/ecommerce/controller/LoginController.java | 6 +++--- .../org/hso/ecommerce/controller/RegisterController.java | 4 ++-- prototype/src/main/resources/templates/register.html | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java index 0138257..94182ce 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java @@ -35,19 +35,19 @@ public class LoginController { Optional user = userRepository.findByEmail(username); if (!user.isPresent()) { - request.setAttribute("error", "Email Adresse falsch."); + request.setAttribute("error", "Die Email Adresse falsch."); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); return "login"; } if (!user.get().validatePassword(password)) { - request.setAttribute("error", "Passwort falsch."); + request.setAttribute("error", "Das Passwort ist falsch."); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); return "login"; } if (!user.get().isActive) { - request.setAttribute("error", "User ist deaktiviert."); + request.setAttribute("error", "Dieses Konto ist deaktiviert.."); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); return "login"; } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index b58099d..36fcdef 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java @@ -31,13 +31,13 @@ public class RegisterController { HttpSession session) { Optional user = userRepository.findByEmail(username); if (user.isPresent()) { - request.setAttribute("error", "Email Adresse existiert bereits!"); + request.setAttribute("error", "Die Email Adresse existiert bereits."); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); return "register"; } if (!password.equals(password2)) { - request.setAttribute("error", "Passwörter sind nicht gleich"); + request.setAttribute("error", "Die Passwörter stimmen nicht überein."); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return "register"; } diff --git a/prototype/src/main/resources/templates/register.html b/prototype/src/main/resources/templates/register.html index a2ef401..de4b839 100644 --- a/prototype/src/main/resources/templates/register.html +++ b/prototype/src/main/resources/templates/register.html @@ -56,9 +56,9 @@
-
+
-
+

Werbung

@@ -66,9 +66,9 @@
-
+
-
+
-- 2.47.1