@RequestMapping(value = "/{fanficId}", method = RequestMethod.POST) public String removeFanfic(@PathVariable("fanficId") int fanficId, HttpServletRequest request) { if (!(request.isUserInRole(Role.ROLE_ADMIN) || fanficService .getFanficById(fanficId) .getAuthor() .getUsername() .equals(request.getRemoteUser()))) { return "redirect:/"; } User author = fanficService.getFanficById(fanficId).getAuthor(); fanficService.removeFanficById(author, fanficId); return "redirect:/user/" + author.getId(); }
private boolean checkInputErrors(User user, Model model) { boolean isErrorInput = false; if (!user.getEmail().matches(".+@.+\\..+") || user.getEmail().length() > 75) { model.addAttribute("notCorrectEmail", true); isErrorInput = true; } if (!user.getUsername().matches("[a-zA-Zà-ÿÀ-ß0-9_]+") || user.getUsername().length() > 30) { model.addAttribute("notCorrectUsername", true); isErrorInput = true; } else { if (userService.isRegistered(user.getUsername())) { model.addAttribute("usernameAlreadyRegistered", true); isErrorInput = true; } } if (!user.getPassword().matches("[a-zA-Zà-ÿÀ-ß0-9_]+") || user.getPassword().length() > 30) { model.addAttribute("notCorrectPassword", true); isErrorInput = true; } return isErrorInput; }
@RequestMapping(method = RequestMethod.POST) public String createUser( @ModelAttribute("user") User user, BindingResult bindingResult, Model model, HttpServletRequest request) { if (checkInputErrors(user, model)) { settingModel(model); return "signUp"; } int registrationId = userService.register(user); ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", LocaleContextHolder.getLocale()); emailService.sendMessage( user.getEmail(), resourceBundle.getString("ifYouRegisteredOnFanficLibraryWebsiteGoTo") + " http://" + request.getServerName() + ":" + request.getServerPort() + "/confirmRegistration/" + registrationId); return "redirect:/messageSent"; }