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 f487afb..629ff60 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java @@ -1,5 +1,6 @@ package org.hso.ecommerce.app; +import org.hso.ecommerce.contoller.Login; import org.hso.ecommerce.db.CustomerRepository; import org.hso.ecommerce.entities.Customer; import org.springframework.beans.factory.annotation.Autowired; @@ -38,12 +39,6 @@ public class RequestController { return "home"; } - @GetMapping("/greeting") - public String greeting(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) { - model.addAttribute("name", name); - return "greeting"; - } - @GetMapping("/articledetail") public String articledetail() { return "articledetail"; @@ -51,12 +46,12 @@ public class RequestController { @GetMapping("/searchresults") public String searchresults() { - return "searchresults"; + return "searchResults"; } @GetMapping("/shoppingcart") public String shoppingcart() { - return "shoppingcart"; + return "shoppingCart"; } @GetMapping("/intern/customerdetail") @@ -133,7 +128,7 @@ public class RequestController { model.addAttribute("zipcode", "12345"); model.addAttribute("country", "Musterland"); - return "customerAccountSettings"; + return "/customer/accountSettings"; } @RequestMapping(value="/updateAccountSettings", method=RequestMethod.POST, params="action=updateAccountSettings") @@ -142,7 +137,7 @@ public class RequestController { System.out.println(customer.username); System.out.println(customer.password); - return "redirect:/customer/accountsettings"; + return "/customer/accountsettings"; } @GetMapping("/login") @@ -154,26 +149,13 @@ public class RequestController { } @RequestMapping(value="/login", method=RequestMethod.POST, params="action=login") public String loginAction(@ModelAttribute Customer customer, HttpServletResponse response) { - // do the login magic and get a loginToken - System.out.println(customer.username); - System.out.println(customer.password); - - List customers = customerRepo.findByUsername(customer.username); - - if (customers.size() == 1 && (customers.get(0).username.equals(customer.username) && customers.get(0).password.equals(customer.password))) { - System.out.println("The login data is valid"); - - String loginToken = UUID.randomUUID().toString(); - - // set the loginToken as session cookie - Cookie cookie = new Cookie("loginToken", loginToken); + Cookie cookie = new Login(customerRepo).getLoginToken(customer); + if (cookie != null) { response.addCookie(cookie); + return "redirect:home"; } else { - System.out.println("The login data is invalid!"); - return "redirect:/login"; // redirect so the input files get cleared, otherwise only pwd gets cleared + return "redirect:login"; // redirect so the input files get cleared, otherwise only pwd gets cleared } - - return "redirect:/home"; } @GetMapping("/register") @@ -195,7 +177,7 @@ public class RequestController { if (customerRepo.findByUsername(customer.username).size() != 0) { // TODO System.out.println("The customer exists already"); - return "register"; + return "redirect:register"; } else { customerRepo.save(customer); System.out.println(customerRepo.findByUsername(customer.username).size()); @@ -207,7 +189,7 @@ public class RequestController { // set the loginToken as session cookie Cookie cookie = new Cookie("loginToken", loginToken); response.addCookie(cookie); - return "redirect:/home"; + return "home"; } @GetMapping("/about") diff --git a/prototype/src/main/java/org/hso/ecommerce/contoller/Login.java b/prototype/src/main/java/org/hso/ecommerce/contoller/Login.java new file mode 100644 index 0000000..e545de8 --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/contoller/Login.java @@ -0,0 +1,41 @@ +package org.hso.ecommerce.contoller; + +import org.hso.ecommerce.db.CustomerRepository; +import org.hso.ecommerce.entities.Customer; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.Cookie; +import java.util.List; +import java.util.UUID; + +public class Login { + + private final CustomerRepository customerRepo; + + @Autowired + public Login(CustomerRepository customerRepo) { + this.customerRepo = customerRepo; + } + + public Cookie getLoginToken(Customer customer) { + // do the login magic and get a loginToken + System.out.println(customer.username); + System.out.println(customer.password); + + List customers = customerRepo.findByUsername(customer.username); + + if (customers.size() == 1 && (customers.get(0).username.equals(customer.username) && customers.get(0).password.equals(customer.password))) { + System.out.println("The login data is valid"); + + String loginToken = UUID.randomUUID().toString(); + + // set the loginToken as session cookie + return new Cookie("loginToken", loginToken); + } else { + System.out.println("The login data is invalid!"); + return null; // redirect so the input files get cleared, otherwise only pwd gets cleared + } + + + } +} diff --git a/prototype/src/main/resources/static/css/dialog.css b/prototype/src/main/resources/static/css/dialog.css deleted file mode 100644 index 114eb80..0000000 --- a/prototype/src/main/resources/static/css/dialog.css +++ /dev/null @@ -1,19 +0,0 @@ -.dialog { - display: none; /* Hidden by default */ - position: fixed; /* Stay in place */ - z-index: 1; - left: 0; - top: 0; - width: 100%; /* Full width */ - height: 100%; /* Full height */ - overflow: auto; /* Enable scroll if needed */ - padding-top: 60px; -} - -.dialog-content { - background-color: var(--c-black); - margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */ - border: 1px solid #888; - width: 50%; /* Could be more or less, depending on screen size */ - -} \ No newline at end of file diff --git a/prototype/src/main/resources/templates/customerAccountSettings.html b/prototype/src/main/resources/templates/customer/accountSettings.html similarity index 79% rename from prototype/src/main/resources/templates/customerAccountSettings.html rename to prototype/src/main/resources/templates/customer/accountSettings.html index 7577315..d891923 100644 --- a/prototype/src/main/resources/templates/customerAccountSettings.html +++ b/prototype/src/main/resources/templates/customer/accountSettings.html @@ -10,57 +10,57 @@
-

Account Settings

+

Account Einstellungen

-

General Settings

+

Einstellungen

- +

- +

- +

- +

-

Shipment Settings

+

Versand

- +

- +

- +

- +

-

Payment Settings

+

Bezahlung

TODO

diff --git a/prototype/src/main/resources/templates/fragments/header.html b/prototype/src/main/resources/templates/fragments/header.html index 71b8aac..6385960 100644 --- a/prototype/src/main/resources/templates/fragments/header.html +++ b/prototype/src/main/resources/templates/fragments/header.html @@ -14,7 +14,7 @@
Login -
+
diff --git a/prototype/src/main/resources/templates/login.html b/prototype/src/main/resources/templates/login.html index 326c0d5..b4cb8f5 100644 --- a/prototype/src/main/resources/templates/login.html +++ b/prototype/src/main/resources/templates/login.html @@ -3,33 +3,53 @@ e-commerce - + - -
-
-
-
- - + +
- - +
+
- - -
+ -
- - Forgot password? -
- -
-
-
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ + + Passwort vergessen? +
+
+ + + +
+ + +
+
diff --git a/prototype/src/main/resources/templates/register.html b/prototype/src/main/resources/templates/register.html index 1d1a78d..a72bdf9 100644 --- a/prototype/src/main/resources/templates/register.html +++ b/prototype/src/main/resources/templates/register.html @@ -9,17 +9,51 @@
-
-
- - - - +
+
+ + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + +
+ +
+ +
+ + -
- +
+