use of softuni.todolist.entity.User in project SoftUni by kostovhg.
the class TodoController method createProcess.
@PostMapping("/todo/create")
@PreAuthorize("isAuthenticated()")
public String createProcess(TodoBindingModel todoBindingModel) {
UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User userEntity = this.userRepository.findByEmail(user.getUsername());
Todo todoEntity = new Todo(todoBindingModel.getTitle(), todoBindingModel.getContent(), userEntity);
this.todoRepository.saveAndFlush(todoEntity);
return "redirect:/";
}
use of softuni.todolist.entity.User 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";
}
use of softuni.todolist.entity.User in project SoftUni by kostovhg.
the class UserController method profilePage.
@GetMapping("/profile")
@PreAuthorize("isAuthenticated()")
public String profilePage(Model model) {
UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User user = this.userRepository.findByEmail(principal.getUsername());
model.addAttribute("user", user);
model.addAttribute("view", "user/profile");
return "base-layout";
}
Aggregations