作者 钟来

添加退出登录接口

@@ -6,10 +6,12 @@ import com.zhonglai.luhui.action.BaseController; @@ -6,10 +6,12 @@ import com.zhonglai.luhui.action.BaseController;
6 import io.swagger.annotations.*; 6 import io.swagger.annotations.*;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import com.zhonglai.luhui.dao.service.PublicService; 8 import com.zhonglai.luhui.dao.service.PublicService;
  9 +import org.springframework.beans.factory.annotation.Value;
9 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.bind.annotation.RequestMethod; 11 import org.springframework.web.bind.annotation.RequestMethod;
11 import org.springframework.web.bind.annotation.RestController; 12 import org.springframework.web.bind.annotation.RestController;
12 13
  14 +import javax.servlet.http.HttpServletRequest;
13 import java.util.regex.Pattern; 15 import java.util.regex.Pattern;
14 16
15 @Api(tags = "用户") 17 @Api(tags = "用户")
@@ -19,6 +21,9 @@ public class UserInfoController extends BaseController { @@ -19,6 +21,9 @@ public class UserInfoController extends BaseController {
19 @Autowired 21 @Autowired
20 protected PublicService publicService ; 22 protected PublicService publicService ;
21 23
  24 + @Value("${token.header}")
  25 + private String LOGIN_TOKEN_KEY;
  26 +
22 @ApiOperation(value = "获取用户信息",notes = "返回参数说明:\n" + 27 @ApiOperation(value = "获取用户信息",notes = "返回参数说明:\n" +
23 "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',\n" + 28 "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',\n" +
24 " `username` varchar(50) NOT NULL COMMENT '用户登录名',\n" + 29 " `username` varchar(50) NOT NULL COMMENT '用户登录名',\n" +
@@ -125,6 +130,16 @@ public class UserInfoController extends BaseController { @@ -125,6 +130,16 @@ public class UserInfoController extends BaseController {
125 return AjaxResult.success(publicService.updateObject(userInfo,"id")); 130 return AjaxResult.success(publicService.updateObject(userInfo,"id"));
126 } 131 }
127 132
  133 + @ApiOperation("退出登录")
  134 + @RequestMapping(value = "signOut", method = RequestMethod.POST)
  135 + public AjaxResult signOut()
  136 + {
  137 + HttpServletRequest request = getRequest();
  138 + request.getSession().removeAttribute(LOGIN_TOKEN_KEY);
  139 + request.getSession().invalidate();
  140 + return AjaxResult.success();
  141 + }
  142 +
128 private static final Pattern DATETIME_PATTERN = 143 private static final Pattern DATETIME_PATTERN =
129 Pattern.compile("^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])\\s(2[0-3]|[01]\\d):[0-5]\\d:[0-5]\\d$"); 144 Pattern.compile("^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])\\s(2[0-3]|[01]\\d):[0-5]\\d:[0-5]\\d$");
130 145