新增记住密码功能

master
xueli.xue 9 years ago
parent baa61b0151
commit 00465f53c6
  1. 8
      xxl-job-admin/src/main/java/com/xxl/job/controller/IndexController.java
  2. 4
      xxl-job-admin/src/main/java/com/xxl/job/controller/interceptor/PermissionInterceptor.java
  3. 13
      xxl-job-admin/src/main/java/com/xxl/job/core/util/CookieUtil.java
  4. 2
      xxl-job-admin/src/main/webapp/WEB-INF/template/login.ftl

@ -42,11 +42,15 @@ public class IndexController {
@RequestMapping(value="login", method=RequestMethod.POST)
@ResponseBody
@PermessionLimit(limit=false)
public ReturnT<String> loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password){
public ReturnT<String> 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<String>(500, "账号或密码错误");
}

@ -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){

@ -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);
}

@ -26,7 +26,7 @@
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
<input type="checkbox" name="ifRemember" > Remember Me
</label>
</div>
</div><!-- /.col -->

Loading…
Cancel
Save