package com.weaver.seconddev.cussso.controller;

import com.weaver.common.authority.annotation.WeaPermission;
import com.weaver.seconddev.cussso.service.CusSSOServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/papi/secondev/sso/custom")
@WeaPermission(publicPermission = true)
public class SecDevAuthCustomController {

    private static final Logger log = LoggerFactory.getLogger(SecDevAuthCustomController.class);
    @Autowired
    private CusSSOServiceImpl cusSSOServiceImpl;

    @RequestMapping(value = "/login")
    public void customLogin(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            String redirectUrl = cusSSOServiceImpl.login(servletRequest, servletResponse).get("redirectUrl");
            servletResponse.sendRedirect(redirectUrl);
        } catch (Exception e) {
            log.error("====>wyw login Redirect error" + e==null?"":e.getMessage());
            log.error("====>wyw login Redirect error", e);
            throw new RuntimeException(e.getMessage());
        }
    }

}
