package com.bytesw.bytebot.controller.sso;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Principal;

@Controller
@Log4j2
@ConditionalOnProperty(
        name="application.services.security",
        havingValue = "oauth2sso",
        matchIfMissing = false)
public class LoginController {

    @RequestMapping(value = {"/home"}, method = RequestMethod.GET)
    public final String home(HttpServletRequest request, HttpServletResponse response, Principal principal) {
        System.out.println("* home *****> " +  request.getSession(false).getId());

        System.out.println(request.getSession().getAttribute("username"));
        return "home";
    }

    @RequestMapping(value = {"/mylogin"})
    public final String mylogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("* mylogin *****> " + request.getSession(false).getId());

        System.out.println(request.getSession().getAttribute("username"));
        return "home";
    }
}

