package de.uni_koeln.spinfo.drc.controller;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import de.uni_koeln.spinfo.drc.model.RegistrationForm;
import de.uni_koeln.spinfo.drc.model.RegistrationFormValidator;

@Controller
public class RegistrationController {
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		binder.setValidator(new RegistrationFormValidator());
	}

	@RequestMapping(value = "/signup", method = RequestMethod.GET)
	public ModelAndView uploadFiles(RegistrationForm registrationForm) {
		ModelAndView mv = new ModelAndView("signup");
		mv.addObject("registrationForm", registrationForm);
		return mv;
	}

	@RequestMapping(value = "/signup", method = RequestMethod.POST)
	public String uploadFiles(@Valid RegistrationForm registrationForm,
			BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return "signup";
		}
		return "redirect:/userCollection";
	}

}

@@ -21,19 +21,22 @@
 .spinfo.
-drc
+upcase
 .control
@@ -38,16 +38,21 @@
 ntroller
+.user
 ;%0A%0Aimpor
@@ -78,16 +78,79 @@
 Valid;%0A%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -346,32 +346,95 @@
 ion.InitBinder;%0A
+import org.springframework.web.bind.annotation.ModelAttribute;%0A
 import org.sprin
@@ -615,35 +615,38 @@
 ni_koeln.spinfo.
-drc
+upcase
 .model.Registrat
@@ -685,11 +685,14 @@
 nfo.
-drc
+upcase
 .mod
@@ -725,60 +725,267 @@
 or;%0A
-%0A@Controller%0Apublic class RegistrationController %7B%0A%09
+import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser;%0Aimport de.uni_koeln.spinfo.upcase.mongodb.repository.UpcaseUserRepository;%0A%0A@Controller%0Apublic class RegistrationController %7B%0A%0A%09@Autowired%0A%09private UpcaseUserRepository upcaseUserRepository;%0A
 %0A%09@I
@@ -1453,16 +1453,52 @@
 s(@Valid
+ @ModelAttribute(%22registrationForm%22)
  Registr
@@ -1559,16 +1559,17 @@
 sult) %7B%0A
+%0A
 %09%09if (bi
@@ -1618,16 +1618,112 @@
 up%22;%0A%09%09%7D
+%0A%0A%09%09upcaseUserRepository.save(new UpcaseUser(registrationForm));%0A%09%09// TODO: Security - USER_ROLE
 %0A%09%09retur

Save user after form validation