Create rudimentary register class
This commit is contained in:
parent
5c5df83872
commit
7686c4cda6
|
@ -69,22 +69,6 @@ public class RequestController {
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/register")
|
|
||||||
public String register() {
|
|
||||||
return "register";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/register")
|
|
||||||
public String registerPost(
|
|
||||||
@RequestParam("username") String username,
|
|
||||||
@RequestParam("password") String password,
|
|
||||||
@RequestParam("password2") String password2,
|
|
||||||
@RequestParam("type") String type
|
|
||||||
) {
|
|
||||||
|
|
||||||
return "redirect:/";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/intern/")
|
@GetMapping("/intern/")
|
||||||
public String intern() {
|
public String intern() {
|
||||||
return "intern/index";
|
return "intern/index";
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package org.hso.ecommerce.controller;
|
||||||
|
|
||||||
|
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 java.util.Optional;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class RegisterController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final UserRepository userRepository = null;
|
||||||
|
|
||||||
|
@PostMapping("/register")
|
||||||
|
public String register(
|
||||||
|
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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Optional<User> user = userRepository.findByEmail(username);
|
||||||
|
if (user.isPresent()) {
|
||||||
|
request.setAttribute("error", "Email Adresse existiert bereits!");
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
User newUser = new User();
|
||||||
|
|
||||||
|
|
||||||
|
return "register";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/register")
|
||||||
|
public String register() {
|
||||||
|
return "register";
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue