package com.zzsn.knowbase.util;

import com.alibaba.fastjson.JSON;
import com.zzsn.knowbase.entity.LoginUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

public class AuthUtil {

    static SimpleDateFormat format;

    public static LoginUser getLoginUser() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String userInfo = request.getHeader("loginUser");
            return JSON.parseObject(userInfo, LoginUser.class);
        }catch (Exception e){
            return null;
        }
    }

}
