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); } } } } }
最近下载更多
genyuan2014 LV6
4月27日
wanglinddad LV55
3月14日
erqiu2013 LV18
2023年12月27日
微笑刺客 LV16
2023年11月21日
Seaskye LV14
2023年11月4日
ssh123 LV10
2023年9月28日
想飞的大肥猪 LV9
2023年8月2日
uni-code_0123 LV1
2023年7月19日
AlanLi LV18
2023年7月6日
dzlwindy LV8
2023年6月29日
最近浏览更多
kenhomeliu LV29
4月30日
genyuan2014 LV6
4月27日
2716804680 LV9
4月20日
educationAAA LV5
4月17日
op123129
4月15日
暂无贡献等级
微信网友_6927932988952576 LV12
3月30日
vluobo LV1
3月19日
kaye7549317
3月18日
暂无贡献等级
wanglinddad LV55
3月14日
uid0901 LV2
3月13日