From 00465f53c6fa64fd9b5465e1cc45420e23247186 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Sat, 14 May 2016 21:58:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=B0=E4=BD=8F=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/controller/IndexController.java | 8 ++++++-- .../interceptor/PermissionInterceptor.java | 4 ++-- .../main/java/com/xxl/job/core/util/CookieUtil.java | 13 +++++++++++-- .../src/main/webapp/WEB-INF/template/login.ftl | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java index a53e0466..84e9145c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java @@ -42,11 +42,15 @@ public class IndexController { @RequestMapping(value="login", method=RequestMethod.POST) @ResponseBody @PermessionLimit(limit=false) - public ReturnT loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password){ + public ReturnT loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password, String ifRemember){ if (!PermissionInterceptor.ifLogin(request)) { if (StringUtils.isNotBlank(userName) && StringUtils.isNotBlank(password) && "admin".equals(userName) && "123456".equals(password)) { - PermissionInterceptor.login(response); + boolean ifRem = false; + if (StringUtils.isNotBlank(ifRemember) && "on".equals(ifRemember)) { + ifRem = true; + } + PermissionInterceptor.login(response, ifRem); } else { return new ReturnT(500, "账号或密码错误"); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/interceptor/PermissionInterceptor.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/interceptor/PermissionInterceptor.java index 05b0c47d..17b2a98b 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/controller/interceptor/PermissionInterceptor.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/interceptor/PermissionInterceptor.java @@ -18,8 +18,8 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter { public static final String LOGIN_IDENTITY_KEY = "LOGIN_IDENTITY"; public static final String LOGIN_IDENTITY_VAL = "sdf!121sdf$78sd!8"; - public static boolean login(HttpServletResponse response){ - CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_VAL); + public static boolean login(HttpServletResponse response, boolean ifRemember){ + CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_VAL, ifRemember); return true; } public static void logout(HttpServletRequest request, HttpServletResponse response){ diff --git a/xxl-job-admin/src/main/java/com/xxl/job/core/util/CookieUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/core/util/CookieUtil.java index fc023719..bc15cba3 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/core/util/CookieUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/core/util/CookieUtil.java @@ -19,10 +19,19 @@ public class CookieUtil { * @param response * @param key * @param value + * @param ifRemember */ - public static void set(HttpServletResponse response, String key, String value) { + public static void set(HttpServletResponse response, String key, String value, boolean ifRemember) { + + int age = COOKIE_MAX_AGE; + if (ifRemember) { + age = COOKIE_MAX_AGE; + } else { + age = -1; + } + Cookie cookie = new Cookie(key, value); - cookie.setMaxAge(COOKIE_MAX_AGE); // Cookie过期时间,单位/秒 + cookie.setMaxAge(age); // Cookie过期时间,单位/秒 cookie.setPath(COOKIE_PATH); // Cookie适用的路径 response.addCookie(cookie); } diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/login.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/login.ftl index c4052006..23db39ad 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/login.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/login.ftl @@ -26,7 +26,7 @@