You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
package org.ros.chatto.controller;
|
|
|
|
import java.security.Principal;
|
|
|
|
import org.ros.chatto.dto.ChatMessageDTO;
|
|
import org.ros.chatto.service.UserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
/*
|
|
@Controller
|
|
@RequestMapping(value = "/test")
|
|
public class TestController {
|
|
|
|
@GetMapping
|
|
public ModelAndView getTestData() {
|
|
ModelAndView mv = new ModelAndView();
|
|
mv.setViewName("welcome");
|
|
mv.getModel().put("data", "Welcome home man");
|
|
|
|
return mv;
|
|
}
|
|
}*/
|
|
|
|
@Controller
|
|
public class Home {
|
|
|
|
@Autowired
|
|
UserService userService;
|
|
|
|
@RequestMapping("/")
|
|
public ModelAndView showPage(Principal principal) {
|
|
ModelAndView mv = new ModelAndView("home");
|
|
mv.addObject("message", "Welcome!");
|
|
// mv.addObject("userNames", userService.findAllOtherUsers(principal.getName()));
|
|
return mv;
|
|
}
|
|
|
|
@GetMapping("/crypt")
|
|
public String showCrypt() {
|
|
return "crypto";
|
|
}
|
|
|
|
@GetMapping("/chat")
|
|
public ModelAndView showChat(Principal principal) {
|
|
ModelAndView modelAndView = new ModelAndView("chat");
|
|
modelAndView.addObject(new ChatMessageDTO());
|
|
// modelAndView.addObject("userNames", userRepositoryCustom.getAllUserNames("hmm"));
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
// Set<String> roles = authentication.getAuthorities().stream().map(r -> r.getAuthority())
|
|
// .collect(Collectors.toSet());
|
|
// for (String r : roles) {
|
|
// System.out.println(r);
|
|
// }
|
|
|
|
// boolean hasUserRole = authentication.getAuthorities().stream()
|
|
// .anyMatch(r -> r.getAuthority().equals("ROLE_USER"));
|
|
|
|
boolean isAdmin = authentication.getAuthorities().stream()
|
|
.anyMatch(r -> r.getAuthority().equals("ROLE_ADMIN") || r.getAuthority().equals("ROLE_SUPER_USER"));
|
|
System.out.println("Is admin? " + isAdmin);
|
|
modelAndView.addObject("userNames", userService.findAllOtherUsers(principal.getName()));
|
|
return modelAndView;
|
|
}
|
|
// public String showHome(Model model)
|
|
// {
|
|
// model.addAttribute("message", "Welcome");
|
|
// return "home";
|
|
// }
|
|
}
|