Search in sources :

Example 1 with Role

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";
}
Also used : Role(softuni.todolist.entity.Role) User(softuni.todolist.entity.User) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 Role (softuni.todolist.entity.Role)1 User (softuni.todolist.entity.User)1