package com.jfinal.club._front;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.club.common.model.Users;
import com.jfinal.club.util.CacheSessionUtil;
import com.jfinal.club.util.Cons;
import org.apache.commons.lang3.StringUtils;

/**
 * @descriptions: 用户session 拦截器
 * @author: lc
 * @date: 2020-05-09 19:47:07
 * @Version: 1.0
 **/
public class FrontUsersInterface implements Interceptor {

    private CacheSessionUtil sessionUtil = CacheSessionUtil.getInstance( );

    @Override
    public void intercept(Invocation inv) {

        String uid = inv.getController( ).getCookie(Cons.USERID);
        if(StringUtils.isNotBlank(uid)){
            Users users = Users.dao.findFirst("select * from users where id = ? ", uid);
            inv.getController().setAttr("users",users);
            inv.invoke();
        }else{
            inv.getController().setAttr("users",null);
            inv.invoke();
        }
    }
}
