I am trying to create a user registration in java. I have already created a Musician class. I am looking to improve the controller. The password currently doesn't work properly and how can I create a user that has a unique identifier?
@Controller
@RequestMapping("musician")
public class MusicianController {
@RequestMapping (value = "")
public String index (Model model) {
model.addAttribute("title", "Musician Connect");
return "musician/index";
}
@RequestMapping (value = "add", method = RequestMethod.GET)
public String add(Model model) {
model.addAttribute(new Musician());
model.addAttribute("title", "Create an Account");
return "musician/add";
}
@RequestMapping(value = "add", method = RequestMethod.POST)
public String add(@ModelAttribute @Valid Musician musician,
Errors errors,
String verify,
Model model) {
model.addAttribute("musician", musician);
boolean passwordsMatch = true;
if (errors.hasErrors()) {
return "musician/add";
}
if (musician.getPassword() == null || verify == null
|| !musician.getPassword().equals(verify)) {
passwordsMatch = false;
}
if (passwordsMatch) {
return "redirect:/login";
}
return "redirect:";
}
I would use Spring Security for user registration. The following tutorials ought to help get you started:
https://spring.io/guides/gs/securing-web/
https://medium.com/@gustavo.ponce.ch/spring-boot-spring-mvc-spring-security-mysql-a5d8545d837d
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.