Subversion Repositories SmartDukaan

Rev

Rev 1957 | Rev 2157 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
458 rajveer 1
package in.shop2020.serving.controllers;
2
 
1957 vikas 3
import in.shop2020.serving.utils.DataLogger;
4
import in.shop2020.serving.utils.DataLogger.Event;
458 rajveer 5
import in.shop2020.thrift.clients.UserContextServiceClient;
6
 
7
import java.util.Date;
8
import javax.servlet.http.Cookie;
9
 
1957 vikas 10
import org.apache.commons.lang.StringUtils;
832 rajveer 11
import org.apache.log4j.Logger;
458 rajveer 12
import org.apache.struts2.convention.annotation.Result;
13
import org.apache.struts2.convention.annotation.Results;
14
 
15
/**
16
 * @author rajveer
17
 *
18
 */
19
@Results({
20
    @Result(name="success", type="redirectAction", 
823 vikas 21
    		params = {"actionName" , "home"})
458 rajveer 22
})
23
 
24
public class LogoutController extends BaseController {
25
 
26
 
27
	/**
28
	 * 
29
	 */
650 rajveer 30
	private static final long serialVersionUID = 1L;
31
	/**
32
	 * 
33
	 */
1957 vikas 34
	private static Logger dataLog = DataLogger.getLogger();
458 rajveer 35
 
36
	public LogoutController() {
37
		super();
38
 
39
	}
40
 
41
    // GET /logout
42
    public String index() throws Exception {
43
		if(this.userinfo.isLoggedIn()){
44
			logoutUser(this.userinfo.getUserId());
45
			this.session.removeAttribute("userinfo");
555 chandransh 46
			Cookie uidCookie = cookiesMap.get("uid");
1713 vikas 47
			uidCookie.setDomain(domainName);
48
			uidCookie.setPath("/");
1658 vikas 49
			uidCookie.setValue("");
555 chandransh 50
			uidCookie.setMaxAge(0);
51
	    	this.response.addCookie(uidCookie);
458 rajveer 52
		}	
1957 vikas 53
		dataLog.info(StringUtils.join(
54
                new String[] { Event.LOGOUT.name(),
55
                        userinfo.getEmail() }, ", "));
458 rajveer 56
		return "success";
57
 
58
    }
59
 
60
 
61
    public boolean logoutUser(long userId) throws Exception{
555 chandransh 62
		UserContextServiceClient userContextServiceClient =new UserContextServiceClient();
63
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
458 rajveer 64
 
65
		userClient.setUserAsLoggedOut(userId, (new Date()).getTime());
66
 
67
    	return true;
68
    }
69
 
70
}