예제 #1
0
 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;
 }
예제 #2
0
 @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";
 }