Subversion Repositories SmartDukaan

Rev

Rev 1713 | Rev 2148 | 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
	 */
832 rajveer 34
	private static Logger log = Logger.getLogger(Class.class);
1957 vikas 35
	private static Logger dataLog = DataLogger.getLogger();
458 rajveer 36
 
37
	public LogoutController() {
38
		super();
39
 
40
	}
41
 
42
    // GET /logout
43
    public String index() throws Exception {
44
		if(this.userinfo.isLoggedIn()){
45
			logoutUser(this.userinfo.getUserId());
46
			this.session.removeAttribute("userinfo");
555 chandransh 47
			Cookie uidCookie = cookiesMap.get("uid");
1713 vikas 48
			uidCookie.setDomain(domainName);
49
			uidCookie.setPath("/");
1658 vikas 50
			uidCookie.setValue("");
555 chandransh 51
			uidCookie.setMaxAge(0);
52
	    	this.response.addCookie(uidCookie);
458 rajveer 53
		}	
1957 vikas 54
		dataLog.info(StringUtils.join(
55
                new String[] { Event.LOGOUT.name(),
56
                        userinfo.getEmail() }, ", "));
458 rajveer 57
		return "success";
58
 
59
    }
60
 
61
 
62
    public boolean logoutUser(long userId) throws Exception{
555 chandransh 63
		UserContextServiceClient userContextServiceClient =new UserContextServiceClient();
64
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
458 rajveer 65
 
66
		userClient.setUserAsLoggedOut(userId, (new Date()).getTime());
67
 
68
    	return true;
69
    }
70
 
71
}