use of org.springframework.security.access.AccessDeniedException in project zhcet-web by zhcet-amu.
the class ProfileController method profile.
@GetMapping
public String profile(Model model) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
model.addAttribute("user", user);
model.addAttribute("page_title", "Profile");
if (user.getType().equals(UserType.STUDENT)) {
studentService.getLoggedInStudent().ifPresent(student -> model.addAttribute("student", student));
} else {
facultyService.getLoggedInMember().ifPresent(facultyMember -> model.addAttribute("faculty", facultyMember));
}
return "user/profile";
}
use of org.springframework.security.access.AccessDeniedException in project zhcet-web by zhcet-amu.
the class ProfileController method saveProfile.
@PostMapping("/details")
@PreAuthorize("@authService.isFullyAuthenticated(principal)")
public String saveProfile(@ModelAttribute @Valid UserDetail userDetail, BindingResult result, RedirectAttributes redirectAttributes) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
if (result.hasErrors()) {
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.user_details", result);
redirectAttributes.addFlashAttribute("user_details", userDetail);
} else {
userService.updateDetails(user, userDetail);
redirectAttributes.addFlashAttribute("success", true);
}
return "redirect:/profile/settings";
}
use of org.springframework.security.access.AccessDeniedException in project zhcet-web by zhcet-amu.
the class NotificationSendingController method handleSentNotification.
@PostMapping
public String handleSentNotification(@Valid Notification notification, BindingResult bindingResult, RedirectAttributes redirectAttribute) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
if (bindingResult.hasErrors()) {
redirectAttribute.addFlashAttribute("notification", notification);
redirectAttribute.addFlashAttribute("org.springframework.validation.BindingResult.notification", bindingResult);
} else {
notification.setSender(user);
notificationSendingService.sendNotification(notification);
redirectAttribute.addFlashAttribute("notification_success", "Notification sending in background");
}
return "redirect:/management/notification/send";
}
use of org.springframework.security.access.AccessDeniedException in project zhcet-web by zhcet-amu.
the class NotificationSendingController method sendNotification.
@GetMapping
public String sendNotification(Model model) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
model.addAttribute("page_title", "Send Notifications");
model.addAttribute("page_subtitle", "Notification Manager");
model.addAttribute("page_description", "Send notifications to students, sections or departments");
model.addAttribute("channel_types", Arrays.asList(ChannelType.STUDENT, ChannelType.COURSE, ChannelType.TAUGHT_COURSE, ChannelType.SECTION, ChannelType.FACULTY));
if (!model.containsAttribute("notification")) {
Notification notification = new Notification();
notification.setSender(user);
model.addAttribute("notification", notification);
}
return "management/send_notification";
}
Aggregations