package com.ruoyi.web.controller.gas;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.framework.web.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: TODO
 * @Author: huangcheng
 * @Date: 2021/11/25
 * @Version V1.0
 */
@Controller
public class PortalController {

    @Value("${system.redirectUrl}")
    private String redirectUrl;

    @Autowired
    private SysLoginService sysLoginService;

    @RequestMapping("/portal/login")
    public String thirdLogin(@RequestParam String token, HttpServletResponse response) {
        // 组装系统本身的token给前端
        String newToken = sysLoginService.nologin(token);
        if (StrUtil.isNotBlank(newToken)) {
            Cookie cookie = new Cookie("Admin-Token", newToken);
            cookie.setPath("/");
            response.addCookie(cookie);
            return "redirect:" + redirectUrl + "?token=" + newToken;
        }
        return "redirect:" + redirectUrl;

    }
}
