package com.product.admin.controller;
|
|
import org.apache.commons.lang3.StringUtils;
|
import com.product.core.cache.DataPoolCacheImpl;
|
import com.product.core.config.CoreConst;
|
import com.product.core.controller.support.AbstractBaseController;
|
import com.product.core.entity.RequestParameterEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.module.sys.config.SystemErrorCode;
|
import com.product.module.sys.version.ApiVersion;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.*;
|
import javax.servlet.http.Cookie;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
/**
|
* 用户结束使用系统
|
* 退出系统清除用户信息
|
*/
|
@RequestMapping
|
@Controller
|
public class LogoutController extends AbstractBaseController {
|
|
|
/**
|
* 退出登录
|
*/
|
@RequestMapping(path = "/logout", method = RequestMethod.POST)
|
@ResponseBody
|
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
|
|
String accessToken = null;
|
Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
|
if (bean != null) {
|
RequestParameterEntity reqp = (RequestParameterEntity) bean;
|
accessToken = reqp.getToken();
|
}
|
if (StringUtils.isBlank(accessToken)) {
|
return this.error(SystemErrorCode.SYSTEM_LOGOUT_PARA_ERROR.getValue(), SystemErrorCode.SYSTEM_LOGOUT_PARA_ERROR.getText());
|
} else {
|
session.invalidate();
|
Cookie[] cookies = request.getCookies();
|
for (Cookie cookie : cookies) {
|
cookie.setMaxAge(0);
|
cookie.setPath("/");
|
response.addCookie(cookie);
|
}
|
try {
|
//退出后清除缓存的中的用户信息
|
DataPoolCacheImpl.getInstance().removeSessionUser();
|
} catch (BaseException e) {
|
return this.error(e);
|
}
|
return OK();
|
}
|
|
}
|
/**
|
* 退出登录
|
*/
|
@RequestMapping(path = "/logout/{version}", method = RequestMethod.POST)
|
@ResponseBody
|
@ApiVersion(1)
|
public String logoutV1(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
|
|
String accessToken = null;
|
Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
|
if (bean != null) {
|
RequestParameterEntity reqp = (RequestParameterEntity) bean;
|
accessToken = reqp.getToken();
|
}
|
if (StringUtils.isBlank(accessToken)) {
|
return this.error(SystemErrorCode.SYSTEM_LOGOUT_PARA_ERROR.getValue(), SystemErrorCode.SYSTEM_LOGOUT_PARA_ERROR.getText());
|
} else {
|
session.invalidate();
|
Cookie[] cookies = request.getCookies();
|
if (cookies != null) {
|
for (Cookie cookie : cookies) {
|
cookie.setMaxAge(0);
|
cookie.setPath("/");
|
response.addCookie(cookie);
|
}
|
}
|
try {
|
//退出后清除缓存的中的用户信息
|
DataPoolCacheImpl.getInstance().removeSessionUser();
|
} catch (BaseException e) {
|
return this.error(e);
|
}
|
return OK();
|
}
|
|
}
|
|
}
|