Merge pull request 'fixes_ui' (#66) from fixes_ui into master
Reviewed-by: Jannik Seiler <seil0@mosad.xyz>
This commit is contained in:
		@ -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> 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";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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> user = userRepository.findByEmail(username);
 | 
			
		||||
		if (!user.isPresent()) {
 | 
			
		||||
			request.setAttribute("error", "Die Email Adresse falsch.");
 | 
			
		||||
			response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
 | 
			
		||||
			return "login";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!user.get().validatePassword(password)) {
 | 
			
		||||
			request.setAttribute("error", "Das Passwort ist falsch.");
 | 
			
		||||
			response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
 | 
			
		||||
			return "login";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!user.get().isActive) {
 | 
			
		||||
			request.setAttribute("error", "Dieses Konto 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:/";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
            @RequestParam("ad") String ad,
 | 
			
		||||
            HttpSession session
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        Optional<User> 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> user = userRepository.findByEmail(username);
 | 
			
		||||
		if (user.isPresent()) {
 | 
			
		||||
			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");
 | 
			
		||||
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
 | 
			
		||||
            return "register";
 | 
			
		||||
        }
 | 
			
		||||
		if (!password.equals(password2)) {
 | 
			
		||||
			request.setAttribute("error", "Die Passwörter stimmen nicht überein.");
 | 
			
		||||
			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";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,78 +1,84 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="de" dir="ltr" xmlns:th="http://www.thymeleaf.org">
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="utf-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
 | 
			
		||||
 | 
			
		||||
    <title>Neuen Account erstellen</title>
 | 
			
		||||
    <link rel="stylesheet" th:href="@{/css/ecom.css}"/>
 | 
			
		||||
 | 
			
		||||
    <script th:src="@{/js/scrollToContent.js}"></script>
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
<nav th:replace="fragments/header :: header">Header</nav>
 | 
			
		||||
<main class="modal">
 | 
			
		||||
    <form class="detailflex m" th:action="@{/register}" method="POST">
 | 
			
		||||
        <div>
 | 
			
		||||
            <h1>Neuen Account erstellen</h1>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div>
 | 
			
		||||
            <h2> Login Daten </h2>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div>
 | 
			
		||||
            <label for="username">Email Adresse</label>
 | 
			
		||||
            <input class="full-width" type="text" name="username" placeholder="Email Adresse" id="username" required>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div>
 | 
			
		||||
            <label for="password">Passwort</label>
 | 
			
		||||
            <input class="full-width" type="password" name="password" placeholder="Passwort" id="password" required>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div>
 | 
			
		||||
            <label for="password2">Passwort wiederholen</label>
 | 
			
		||||
            <input class="full-width" type="password" name="password2" placeholder="Passwort" id="password2" required>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div>
 | 
			
		||||
            <h2> Rechungs- und Lieferinformation </h2>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div class="col-2">
 | 
			
		||||
   <head>
 | 
			
		||||
      <meta charset="utf-8">
 | 
			
		||||
      <meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
 | 
			
		||||
      <title>Neuen Account erstellen</title>
 | 
			
		||||
      <link rel="stylesheet" th:href="@{/css/ecom.css}"/>
 | 
			
		||||
      <script th:src="@{/js/scrollToContent.js}"></script>
 | 
			
		||||
   </head>
 | 
			
		||||
   <body>
 | 
			
		||||
      <nav th:replace="fragments/header :: header">Header</nav>
 | 
			
		||||
      <main class="modal">
 | 
			
		||||
         <form class="detailflex m" th:action="@{/register}" method="POST">
 | 
			
		||||
            <div>
 | 
			
		||||
                <label for="salutation">Anrede</label>
 | 
			
		||||
                <input class="full-width" list="salutationsOpt" name="salutation" id="salutation" placeholder="Anrede"
 | 
			
		||||
                       required/>
 | 
			
		||||
                <datalist id="salutationsOpt">
 | 
			
		||||
                    <option value="Herr">
 | 
			
		||||
                    <option value="Frau">
 | 
			
		||||
                    <option value="Herr Dr.">
 | 
			
		||||
                    <option value="Frau Dr.">
 | 
			
		||||
                </datalist>
 | 
			
		||||
               <h1>Neuen Account erstellen</h1>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
                <label for="name">Name</label>
 | 
			
		||||
                <input class="full-width" type="text" name="name" id="name" placeholder="Nachname Vorname" required/>
 | 
			
		||||
               <h2> Login Daten </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div>
 | 
			
		||||
            <div>
 | 
			
		||||
               <label for="username">Email Adresse</label>
 | 
			
		||||
               <input class="full-width" type="text" name="username" placeholder="Email Adresse" id="username" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
               <label for="password">Passwort</label>
 | 
			
		||||
               <input class="full-width" type="password" name="password" placeholder="Passwort" id="password" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
               <label for="password2">Passwort wiederholen</label>
 | 
			
		||||
               <input class="full-width" type="password" name="password2" placeholder="Passwort" id="password2" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
               <h2> Rechungs- und Lieferinformation </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="col-2">
 | 
			
		||||
               <div>
 | 
			
		||||
                  <label for="salutation">Anrede</label>
 | 
			
		||||
                  <input class="full-width" list="salutationsOpt" name="salutation" id="salutation" placeholder="Anrede"
 | 
			
		||||
                     required/>
 | 
			
		||||
                  <datalist id="salutationsOpt">
 | 
			
		||||
                     <option value="Herr">
 | 
			
		||||
                     <option value="Frau">
 | 
			
		||||
                     <option value="Herr Dr.">
 | 
			
		||||
                     <option value="Frau Dr.">
 | 
			
		||||
                  </datalist>
 | 
			
		||||
               </div>
 | 
			
		||||
               <div>
 | 
			
		||||
               <label for="name">Name</label>
 | 
			
		||||
               <input class="full-width" type="text" name="name" id="name" placeholder="Nachname Vorname" required/>
 | 
			
		||||
               </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
            <label for="address">Anschrift</label>
 | 
			
		||||
            <textarea rows="5" class="full-width" type="text" name="address" id="address"
 | 
			
		||||
                      placeholder="Optional: Zusatz
Optional: Unternehmen
Straße Hausnummer
Postleitzeit Ort
Land"></textarea>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div>
 | 
			
		||||
               placeholder="Optional: Zusatz
Optional: Unternehmen
Straße Hausnummer
Postleitzeit Ort
Land"></textarea>
 | 
			
		||||
            </div>
 | 
			
		||||
            <fieldset>
 | 
			
		||||
            <input type="radio" id="type-priv" name="type" value="priv">
 | 
			
		||||
            <label for="type-priv">Ich bin Privatkunde</label><br>
 | 
			
		||||
            <input type="radio" id="type-bus" name="type" value="bus">
 | 
			
		||||
            <label for="type-bus">Ich bin Geschäftskunde</label><br>
 | 
			
		||||
            </fieldset>
 | 
			
		||||
            <div>
 | 
			
		||||
            <h2> Werbung </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
            <fieldset>
 | 
			
		||||
            <input type="radio" id="ad-y" name="ad" value="y">
 | 
			
		||||
            <label for="ad-y">Ich möchte Werbung erhalten.</label><br>
 | 
			
		||||
            <input type="radio" id="ad-n" name="ad" value="n">
 | 
			
		||||
            <label for="ad-n">Ich möchte keine Werbung erhalten.</label><br>  
 | 
			
		||||
            </fieldset>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
            <button class="full-width" type="submit" name="action" value="login">Registeren</button>
 | 
			
		||||
            <a th:href="@{/terms}">
 | 
			
		||||
                Unsere AGBs finden sie hier.
 | 
			
		||||
            Unsere AGBs finden sie hier.
 | 
			
		||||
            </a>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
    </form>
 | 
			
		||||
</main>
 | 
			
		||||
<footer th:replace="fragments/footer :: footer"></footer>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
            </div>
 | 
			
		||||
         </form>
 | 
			
		||||
      </main>
 | 
			
		||||
      <footer th:replace="fragments/footer :: footer"></footer>
 | 
			
		||||
   </body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user