Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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