package com.tarena.oss.web.actions;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tarena.oss.admin.pojo.Admin;
import com.tarena.oss.admin.service.AdminMgmtService;
import com.tarena.oss.pricing.service.PricingMgmtService;
import com.tarena.oss.rights.pojo.Module;
import com.tarena.oss.util.RightsTools;

public class LoginAction extends Action {
	private AdminMgmtService service;
	
	public void setService(AdminMgmtService service) {
		this.service = service;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String userName=request.getParameter("loginname");
		String password=request.getParameter("password");
		Admin admin=service.lgoin(userName, password);
		System.out.println(admin.toString()+"====admin===");
		if(admin==null ){
			return mapping.findForward("false");
		}
		else{
			Set<Module> modules = RightsTools.getModules(admin);
			System.out.println(modules.size()+"===size()===");
			System.out.println(modules.toString()+"===modules===");
			request.getSession().setAttribute("ADMIN", admin);
			request.getSession().setAttribute("ADMIN_MODULES", modules);
			return mapping.findForward("success");
		}
	}

}
