
package managedbean.common;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


public class SessionUtils {

	public static HttpSession getSession() {
		return (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
	}

	public static HttpServletRequest getRequest() {
		return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	}

	public static boolean isLogedIn() {
		if (getUserId() == "")
			return false;
		else
			return true;
	}
	
	public static String getUserName() {
		HttpSession session = getSession();
		if (session != null && session.getAttribute("username") != null)
			return session.getAttribute("username").toString();
		else
			return "";
	}

	public static String getUserId() {
		HttpSession session = getSession();
		if (session != null && session.getAttribute("userid") != null)
			return session.getAttribute("userid").toString();
		else
			return "";
	}
}
