コード例 #1
0
 @RequestMapping(value = "/register", method = RequestMethod.POST)
 public String register(
     Model model,
     Locale locale,
     @RequestParam(value = "username") String username,
     @RequestParam(value = "password") String password,
     @RequestParam(value = "passwordVerify") String passwordVerify,
     @RequestParam(value = "firstName") String firstName,
     @RequestParam(value = "lastName") String lastName,
     @RequestParam(value = "email") String email,
     @ModelAttribute(value = "user") @Valid User user,
     BindingResult bindingResultUser) {
   log.debug("Creating user... " + username);
   model.addAttribute("properties", propertyService.findOneById(1L));
   if (!password.equals(passwordVerify)) {
     bindingResultUser.rejectValue("passwordVerify", "error.passwordVerify", "Do not match.");
   }
   if (username.contains("admin")) {
     bindingResultUser.rejectValue("username", "error.username", "You can't use this username.");
   }
   if (bindingResultUser.hasErrors()) {
     model.addAttribute("settings", settingRepository.findOneByCode(locale.getLanguage()));
     return propertyService.getTemplate() + "/register";
   }
   User usr = userService.findOneByUsername(username);
   if (usr != null) {
     log.debug("Username value: " + usr.getUsername());
   }
   if (usr == null) {
     log.debug("Username NOT found");
     User usr2 = userService.findOneByEmail(email);
     if (usr2 != null) { // email found
       log.debug("Email already exists. Register with this email.");
       userService.deleteUserEmail(usr2.getId()); // Clean
       userService.createUserAccount(
           username,
           password,
           passwordVerify,
           firstName,
           lastName,
           usr2.getEmail(),
           true,
           "ROLE_USER",
           "user"); // Add
     } else {
       userService.createUserAccount(
           username,
           password,
           passwordVerify,
           firstName,
           lastName,
           email,
           true,
           "ROLE_USER",
           "user");
     }
   }
   return "redirect:/login";
 }
コード例 #2
0
 @RequestMapping(value = "/register", method = RequestMethod.GET)
 public String registerForm(
     Model model,
     Locale locale,
     @ModelAttribute(value = "user") @Valid User user,
     BindingResult bindingResultUser) {
   if (bindingResultUser.hasErrors()) {
     // model.addAttribute("user", user);
   }
   String lang = locale.getLanguage();
   model.addAttribute("settings", settingRepository.findOneByCode(locale.getLanguage()));
   model.addAttribute("pages", pageRepository.findAllByCode(lang));
   model.addAttribute("properties", propertyService.findOneById(1L));
   return propertyService.getTemplate() + "/register";
 }