|
@@ -8,8 +8,10 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import org.thymeleaf.util.StringUtils;
|
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -25,20 +27,49 @@ public class ViewController {
|
|
|
private final String LOGIN_INFO_ADDRESS="http://login.codeshop.com/login/info?token=";
|
|
|
|
|
|
@RequestMapping("/vip")
|
|
|
- public String toLogin(@CookieValue(required = false,value = "TOKEN")Cookie cookie, HttpSession session){
|
|
|
+ public String toLogin(@CookieValue(required = false,value = "TOKEN")Cookie cookie, HttpSession session,HttpServletResponse response) throws IOException {
|
|
|
+ //如果有cookie,进入界面
|
|
|
if (cookie!=null){
|
|
|
String token=cookie.getValue();
|
|
|
if(!StringUtils.isEmpty(token)){
|
|
|
+ //获取用户数据
|
|
|
Map result = restTemplate.getForObject(LOGIN_INFO_ADDRESS + token, Map.class);
|
|
|
//保存用户
|
|
|
session.setAttribute("loginUser",result);
|
|
|
}
|
|
|
+ //如果cookie没有,跳回登录界面
|
|
|
+ }else {
|
|
|
+ String url="http://login.codeshop.com/view/login?target=http://vip.codeshop.com/view/vip";
|
|
|
+ response.sendRedirect(url);
|
|
|
}
|
|
|
return "index";
|
|
|
}
|
|
|
|
|
|
- @RequestMapping("/remove")
|
|
|
- public String removeLogin(){
|
|
|
+ /**
|
|
|
+ * 退出数据
|
|
|
+ * @param cookie
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @RequestMapping("/delete")
|
|
|
+ public String deleteLogin(@CookieValue(required = false,value = "TOKEN")Cookie cookie, HttpServletRequest request
|
|
|
+ , HttpServletResponse response) throws IOException {
|
|
|
+ if (cookie!=null){
|
|
|
+ String token=cookie.getValue();
|
|
|
+ if(!StringUtils.isEmpty(token)){
|
|
|
+ //删除cookie
|
|
|
+ Cookie cookie1=new Cookie("TOKEN",null);
|
|
|
+ cookie1.setDomain("codeshop.com");
|
|
|
+ cookie1.setMaxAge(0);
|
|
|
+ cookie1.setPath("/");
|
|
|
+ response.addCookie(cookie1);
|
|
|
+ //跳转回登录界面
|
|
|
+ String url="http://login.codeshop.com/view/login?target=http://vip.codeshop.com/view/vip";
|
|
|
+ response.sendRedirect(url);
|
|
|
+ }
|
|
|
+ }
|
|
|
return "index";
|
|
|
}
|
|
|
}
|