| 458 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
7 |
|
|
|
8 |
import java.io.UnsupportedEncodingException;
|
|
|
9 |
import java.util.Date;
|
|
|
10 |
|
|
|
11 |
import javax.servlet.http.Cookie;
|
|
|
12 |
|
|
|
13 |
import org.apache.juli.logging.Log;
|
|
|
14 |
import org.apache.juli.logging.LogFactory;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
17 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
18 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
19 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
20 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
21 |
import org.apache.thrift.TException;
|
|
|
22 |
|
|
|
23 |
import com.opensymphony.xwork2.ModelDriven;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @author rajveer
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
@Results({
|
|
|
30 |
@Result(name="success", type="redirectAction",
|
|
|
31 |
params = {"actionName" , "entity/1000111"})
|
|
|
32 |
})
|
|
|
33 |
|
|
|
34 |
public class LogoutController extends BaseController {
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
*/
|
|
|
40 |
private static Log log = LogFactory.getLog(LogoutController.class);
|
|
|
41 |
|
|
|
42 |
private String id;
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
public LogoutController() {
|
|
|
47 |
super();
|
|
|
48 |
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
// GET /logout
|
|
|
52 |
public String index() throws Exception {
|
|
|
53 |
if(this.userinfo.isLoggedIn()){
|
|
|
54 |
logoutUser(this.userinfo.getUserId());
|
|
|
55 |
this.session.removeAttribute("userinfo");
|
|
|
56 |
Cookie cookie1 = new Cookie("userid","");
|
|
|
57 |
cookie1.setMaxAge(0);
|
|
|
58 |
this.response.addCookie(cookie1);
|
|
|
59 |
}
|
|
|
60 |
return "success";
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
* @param id
|
|
|
67 |
*/
|
|
|
68 |
public void setId(String id) {
|
|
|
69 |
this.id = id;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public boolean logoutUser(long userId) throws Exception{
|
|
|
73 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
74 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
75 |
|
|
|
76 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
77 |
userClient = userContextServiceClient.getClient();
|
|
|
78 |
|
|
|
79 |
userClient.setUserAsLoggedOut(userId, (new Date()).getTime());
|
|
|
80 |
|
|
|
81 |
return true;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
}
|