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
	 */
650 rajveer 32
	private static final long serialVersionUID = 1L;
33
	/**
34
	 * 
35
	 */
458 rajveer 36
	private static Log log = LogFactory.getLog(LogoutController.class);
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");
555 chandransh 48
			Cookie uidCookie = cookiesMap.get("uid");
49
			uidCookie.setMaxAge(0);
50
	    	this.response.addCookie(uidCookie);
458 rajveer 51
		}	
52
		return "success";
53
 
54
    }
55
 
56
 
57
    public boolean logoutUser(long userId) throws Exception{
555 chandransh 58
		UserContextServiceClient userContextServiceClient =new UserContextServiceClient();
59
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
458 rajveer 60
 
61
		userClient.setUserAsLoggedOut(userId, (new Date()).getTime());
62
 
63
    	return true;
64
    }
65
 
66
}