@RequestMapping(value = "/login", method = RequestMethod.POST) public String login( @RequestParam String alies, @RequestParam String clau, HttpSession session, Locale locale, Model model) { Persona persona = personaService.getPersona(alies); if (persona != null && persona.getClau().equals(clau)) { session.setAttribute("persona", persona); session.setAttribute("data", obtenirData(locale)); return "redirect:/"; } else { ResourceBundle rb = ResourceBundle.getBundle("messages", locale); model.addAttribute("errorLogin", rb.getString("index.label.error.login")); return "index"; } }
@RequestMapping(value = "/registre", method = RequestMethod.POST) public String registre( @RequestParam String nom, @RequestParam String primerLlinatge, @RequestParam String segonLlinatge, @RequestParam String correu, @RequestParam String alies, @RequestParam String clau, HttpSession session, Locale locale, Model model) { ResourceBundle rb = ResourceBundle.getBundle("messages", locale); boolean hiHaError = false; if (nom == null || nom.isEmpty()) { model.addAttribute("errorNom", rb.getString("index.label.error.nom")); hiHaError = true; } if (primerLlinatge == null || primerLlinatge.isEmpty()) { model.addAttribute("errorPrimerLlinatge", rb.getString("index.label.error.primerLlinatge")); hiHaError = true; } if (correu == null || correu.isEmpty()) { model.addAttribute("errorCorreu", rb.getString("index.label.error.correu")); hiHaError = true; } if (alies == null || alies.isEmpty()) { model.addAttribute("errorAlies", rb.getString("index.label.error.alies")); hiHaError = true; } if (clau == null || clau.isEmpty()) { model.addAttribute("errorClau", rb.getString("index.label.error.clau")); hiHaError = true; } Persona p = personaService.getPersona(alies); if (p != null) { model.addAttribute("errorRegistre", rb.getString("index.label.error.registre")); hiHaError = true; } if (hiHaError) { return "index"; } Persona persona = Util.inserirPersona( nom, primerLlinatge, segonLlinatge, null, correu, alies, clau, null, new Date()); Set<ConstraintViolation<Persona>> errors = validador.validateProperty(persona, "correu"); if (errors.isEmpty()) { personaService.insereixPersona(persona); session.setAttribute("persona", persona); session.setAttribute("data", obtenirData(locale)); return "redirect:/"; } model.addAttribute("errorCorreu", rb.getString("index.label.error.correu.format")); return "index"; }