package com.hzya.frame.web.action;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;

public class SessionContext {

	private static Log logger = LogFactory.getLog(SessionContext.class);

	private SessionContext() {
	}



	//获取当前登录对象
	public static JSONObject getCurrentUser(){
		HttpServletRequest request = WebContext.getRequest();
		JSONObject current_user = (JSONObject) request.getSession().getAttribute("_CURRENT_USER");
		return current_user;
	}
	/**
	 * 设置用户到session中
	 *
	 * @param userObj
	 * @return
	 */
	public static boolean setCurrentUser(JSONObject userObj) {
		HttpServletRequest request = WebContext.getRequest();
		boolean flag = true;
		request.getSession().setAttribute("_CURRENT_USER", userObj);
		return flag;
	}

	/**
	 * 删除当前用户
	 *
	 * @param
	 * @return
	 */
	public static boolean removeCurrentUser() {
		boolean flag = true;
		HttpServletRequest request = WebContext.getRequest();
		request.getSession().removeAttribute("_CURRENT_USER");
		return flag;
	}

}
