use of softuni.todolist.entity.Role in project SoftUni by kostovhg.
the class UserController method registerProcess.
@PostMapping("/register")
public String registerProcess(UserBindingModel userBindingModel) {
if (!userBindingModel.getPassword().equals(userBindingModel.getConfirmPassword())) {
return "redirect:/register";
}
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
User user = new User(userBindingModel.getEmail(), userBindingModel.getFullName(), bCryptPasswordEncoder.encode(userBindingModel.getPassword()));
Role userRole = this.roleRepository.findByName("ROLE_USER");
user.addRole(userRole);
this.userRepository.saveAndFlush(user);
return "redirect:/login";
}
Aggregations