Ignore:
Timestamp:
04/19/23 21:19:08 (19 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
950fa0d
Parents:
9050790
Message:

Add admin functionality and business admin functionality.

Location:
src/main/java/edu/gjoko/schedlr/controllers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/controllers/AdminController.java

    r9050790 r8bcd64c  
    11package edu.gjoko.schedlr.controllers;
    22
     3import org.springframework.security.core.Authentication;
     4import org.springframework.security.core.context.SecurityContextHolder;
    35import org.springframework.stereotype.Controller;
    46import org.springframework.ui.Model;
    57import org.springframework.web.bind.annotation.GetMapping;
     8
     9import javax.servlet.http.HttpServletRequest;
     10import java.security.Principal;
    611
    712@Controller
     
    914
    1015    @GetMapping(path = "/admin")
    11     public String getAdminPageTemplate(Model model) {
     16    public String getAdminPageTemplate(Model model, HttpServletRequest request) {
    1217        return "admin";
    1318    }
     19
     20    @GetMapping(path = "/business_admin")
     21    public String getBusinessAdminPageTemplate(Model model, HttpServletRequest request) {
     22        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
     23        String currentPrincipalName = authentication.getName();
     24
     25        return "business_admin";
     26    }
     27
     28
    1429}
  • src/main/java/edu/gjoko/schedlr/controllers/HomePageController.java

    r9050790 r8bcd64c  
    66import org.springframework.web.bind.annotation.PostMapping;
    77
    8 import java.security.Principal;
    9 
    108@Controller
    119public class HomePageController {
    1210
    1311    @GetMapping(path = "/homepage")
    14     public String getHomePageTemplate(Model model, Principal principal) {
    15         System.out.println(principal);
     12    public String getHomePageTemplate(Model model) {
    1613        return "homepage";
    1714    }
  • src/main/java/edu/gjoko/schedlr/controllers/LoginController.java

    r9050790 r8bcd64c  
    77import org.springframework.web.bind.annotation.ModelAttribute;
    88import org.springframework.web.bind.annotation.PostMapping;
     9import org.springframework.web.bind.annotation.RequestParam;
     10
     11import java.security.Principal;
    912
    1013@Controller
     
    1215
    1316    @GetMapping(path = "/login")
    14     public String getMapping(@ModelAttribute Stakeholder customer, Model model) {
     17    public String getMapping(@RequestParam(value = "error", required = false) String error,
     18                             @ModelAttribute Stakeholder customer, Model model) {
    1519        return "login";
    1620    }
  • src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java

    r9050790 r8bcd64c  
    2828    @PostMapping(path = "/register_customer")
    2929    public String registerCustomer(@ModelAttribute Stakeholder customer, Model model) {
    30         Stakeholder user = stakeholderService.saveStakeholder(customer);
     30        stakeholderService.saveStakeholder(customer);
    3131        return "redirect:login";
    3232    }
  • src/main/java/edu/gjoko/schedlr/controllers/rest/BusinessController.java

    r9050790 r8bcd64c  
    44import edu.gjoko.schedlr.services.BusinessService;
    55import lombok.AllArgsConstructor;
     6import org.springframework.security.core.Authentication;
     7import org.springframework.security.core.context.SecurityContextHolder;
    68import org.springframework.web.bind.annotation.*;
    79
     10import javax.servlet.http.HttpServletRequest;
    811import java.util.List;
    912
     
    2932        businessService.updateBusinesses(businessList);
    3033    }
     34
     35    @GetMapping(path = "/me")
     36    public Business getPersonalInfo(HttpServletRequest request) {
     37        Long businessOwnerId = (long) request.getSession(true).getAttribute("stakeholderId");
     38        return businessService.findByOwner(businessOwnerId);
     39    }
    3140}
Note: See TracChangeset for help on using the changeset viewer.