source: src/main/java/mk/ukim/finki/wp/db/controller/PageController.java

Last change on this file was 5ea00d7, checked in by Malek Alavi <malekalavi7@…>, 8 days ago

Initial project upload

  • Property mode set to 100644
File size: 922 bytes
Line 
1package mk.ukim.finki.wp.db.controller;
2
3import org.springframework.security.core.Authentication;
4import org.springframework.security.core.GrantedAuthority;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8
9@Controller
10public class PageController {
11
12 @GetMapping("/")
13 public String getIndexPage(Model model, Authentication authentication) {
14 boolean loggedIn = authentication != null && authentication.isAuthenticated();
15 model.addAttribute("loggedIn", loggedIn);
16
17 String userRole = null;
18
19 if (loggedIn) {
20 userRole = authentication.getAuthorities().stream()
21 .map(GrantedAuthority::getAuthority)
22 .findFirst()
23 .orElse(null);
24 }
25
26 model.addAttribute("userRole", userRole);
27 return "index";
28 }
29}
Note: See TracBrowser for help on using the repository browser.