fixes_ui #66

Merged
Seil0 merged 3 commits from fixes_ui into master 2020-06-13 11:03:21 +02:00
3 changed files with 123 additions and 128 deletions
Showing only changes of commit a41889b2cb - Show all commits

View File

@ -1,17 +1,7 @@
package org.hso.ecommerce.app; 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.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; 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 * TODO clean up this class
@ -19,62 +9,6 @@ import java.util.Optional;
@Controller @Controller
public class RequestController { 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/") @GetMapping("/intern/customerOrders/")
public String internCustomerOrder() { public String internCustomerOrder() {
return "intern/customerOrders/index"; return "intern/customerOrders/index";
@ -84,5 +18,4 @@ public class RequestController {
public String internCustomerOrdersId() { public String internCustomerOrdersId() {
return "intern/customerOrders/id"; return "intern/customerOrders/id";
} }
} }

View File

@ -1,8 +1,69 @@
package org.hso.ecommerce.controller; 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.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 @Controller
//@RequestMapping("...") @RequestMapping("/")
public class LoginController { 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", "Email Adresse falsch.");
Outdated
Review

Wäre "Die Email Adresse ist falsch." nicht besser?

Generell würde ich für Email und Passwort die gleiche Fehlermeldung zurück geben ("Die Email Adresse oder das Passwort ist falsch.").

Wäre "Die Email Adresse ist falsch." nicht besser? Generell würde ich für Email und Passwort die gleiche Fehlermeldung zurück geben ("Die Email Adresse oder das Passwort ist falsch.").
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
return "login";
}
if (!user.get().validatePassword(password)) {
request.setAttribute("error", "Passwort falsch.");
Outdated
Review

Wäre “Das Passwort ist falsch.” nicht besser?

Wäre “Das Passwort ist falsch.” nicht besser?
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
return "login";
}
if (!user.get().isActive) {
request.setAttribute("error", "User ist deaktiviert.");
Outdated
Review

Wäre “Dieses Konto ist deaktiviert.” nicht besser?

Wäre “Dieses Konto ist deaktiviert.” nicht besser?
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:/";
}
} }

View File

@ -22,20 +22,13 @@ public class RegisterController {
private final UserRepository userRepository = null; private final UserRepository userRepository = null;
@PostMapping("/register") @PostMapping("/register")
public String registerPost( public String registerPost(HttpServletRequest request, HttpServletResponse response,
HttpServletRequest request, @RequestParam("username") String username, @RequestParam("password") String password,
HttpServletResponse response, @RequestParam("password2") String password2, @RequestParam("salutation") String salutation,
@RequestParam("username") String username, @RequestParam("name") String name, @RequestParam("address") String address,
@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("type") String type, // TODO store
@RequestParam("ad") String ad, // TODO store @RequestParam("ad") String ad, // TODO store
HttpSession session HttpSession session) {
)
{
Optional<User> user = userRepository.findByEmail(username); Optional<User> user = userRepository.findByEmail(username);
if (user.isPresent()) { if (user.isPresent()) {
request.setAttribute("error", "Email Adresse existiert bereits!"); request.setAttribute("error", "Email Adresse existiert bereits!");
Outdated
Review

Auch hier "Die Email Adresse existiert bereits." ?

Auch hier "Die Email Adresse existiert bereits." ?
@ -71,9 +64,17 @@ public class RegisterController {
user = userRepository.findByEmail(username); user = userRepository.findByEmail(username);
session.setAttribute("userId", user.get().getId()); session.setAttribute("userId", user.get().getId());
String gto = (String) session.getAttribute("afterLogin");
//login after register
if (gto != null && gto.startsWith("/")) {
return "redirect:" + gto;
} else {
return "redirect:/"; return "redirect:/";
} }
}
@GetMapping("/register") @GetMapping("/register")
public String register() { public String register() {
return "register"; return "register";