@RequestMapping(value = "/messages", method = RequestMethod.POST) public String createMessage(Message msg, Principal principal) { String email = principal.getName(); User user = userRepository.findByEmail(email); msg.setCreatedBy(user); msg.setCreatedOn(new Date()); messageRepository.save(msg); return "redirect:/home"; }
@RequestMapping(value = "/registration", method = RequestMethod.POST) public String registrationForm(User user, Errors errors) { if (errors.hasErrors()) { return "registration"; } User userObj = userRepository.findByEmail(user.getEmail()); if (userObj != null) { errors.rejectValue("email", "email.exists", "Email already in use"); return "registration"; } userRepository.save(user); return "redirect:/login"; }