package controllers; import java.util.Map; import javax.servlet.http.Cookie; import rbac.impl.DefaultRbacService; import com.et.mvc.filter.BeforeFilter; @BeforeFilter(execute="auth", except={"login","logout"}) public class HomeController extends ApplicationController{ public void index(){ } public void login(String username, String password) throws Exception { if (request.getMethod().equalsIgnoreCase("post")){ rbac = new DefaultRbacService(request); Map<String,Object> result = rbac.login(username, password); if (result.get("success") != null){ deleteCookie(); Cookie c = new Cookie("sessionId", result.get("sessionId").toString()); c.setMaxAge(240*3600); c.setPath(request.getContextPath()); response.addCookie(c); redirect("/home/index"); } else { flash.setAttribute("errors", result.get("errors")); redirect("/home/login"); } } } public void logout() throws Exception { rbac = new DefaultRbacService(request); rbac.logout(); deleteCookie(); redirect("/home/index"); } private void deleteCookie(){ Cookie[] cookies = request.getCookies(); if (cookies != null){ for(Cookie cookie: cookies){ if (cookie.getName().equals("sessionId")){ cookie.setMaxAge(0); response.addCookie(cookie); } } } } }

hubugai1 LV11
4月25日
天涯过客JC LV1
4月15日
lhm789 LV6
2024年10月26日
233002037 LV3
2024年10月12日
educationAAA LV11
2024年5月17日
genyuan2014 LV6
2024年4月27日
wanglinddad LV55
2024年3月14日
erqiu2013 LV18
2023年12月27日
微笑刺客 LV21
2023年11月21日
Seaskye LV14
2023年11月4日

ES大兵 LV11
6月12日
暂无贡献等级
hubugai1 LV11
4月24日
付洋麟 LV5
4月23日
天涯过客JC LV1
4月15日
微信网友_6040315240812544 LV8
3月21日
weishenme1993 LV9
1月1日
sshiqi LV2
2024年12月11日
yimaoermao LV1
2024年11月28日
驱蚊器我
2024年11月18日
暂无贡献等级