Subversion Repositories SmartDukaan

Rev

Rev 1553 | Rev 1658 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1553 Rev 1614
Line 35... Line 35...
35
	
35
	
36
	@Override
36
	@Override
37
	public String intercept(ActionInvocation invocation) throws Exception {
37
	public String intercept(ActionInvocation invocation) throws Exception {
38
		final Object action = invocation.getAction();
38
		final Object action = invocation.getAction();
39
        
39
        
-
 
40
		log.info("inside user intercepror");
-
 
41
		
40
        HttpServletRequest request = ServletActionContext.getRequest();
42
        HttpServletRequest request = ServletActionContext.getRequest();
41
        
-
 
42
        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
43
        log.info("url " + request.getRequestURL());
43
        log.info("User browser is:" + userAgent.getBrowser() + " OS is:" + userAgent.getOperatingSystem());
44
        log.info("uri " + request.getRequestURI());
44
        
-
 
45
        
-
 
46
        HttpSession session = request.getSession(); // Get the existing session or create a new one
45
        HttpSession session = request.getSession(); // Get the existing session or create a new one
47
        
46
        
48
        //getCookiesMap(request);
47
        //getCookiesMap(request);
49
		createCookiesMap(request);
48
		createCookiesMap(request);
50
		
49
		
51
		// If the request is for an active session.
50
		// If the request is for an active session.
52
		UserSessionInfo userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
51
		UserSessionInfo userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
53
		
52
		
54
		// Set the userinfo and the uid cookie if they're not already set.
53
		// Set the userinfo and the uid cookie if they're not already set.
55
		if (userInfo == null) {
54
		if (userInfo == null) {
56
			/* Code for bitwalked. No more used.
-
 
57
			if(userAgent.getBrowser().getBrowserType() == BrowserType.WEB_BROWSER){
-
 
58
				userInfo = createAndGetSessionFromUIDCookie(session);
-
 
59
			}else{
-
 
60
				userInfo = new UserSessionInfo();
-
 
61
			}
-
 
62
			*/
-
 
63
			userInfo = createAndGetSessionFromUIDCookie(session);
55
			userInfo = createAndGetSessionFromUIDCookie(session);
64
			session.setAttribute(USER_INFO, userInfo);
56
			session.setAttribute(USER_INFO, userInfo);
65
		}
57
		}
66
		else {
58
		else {
67
			// Update user cookie in case of new registration and login.
59
			// Update user cookie in case of new registration and login.
-
 
60
			if(userInfo.getUserId() != -1){
68
		    createUserCookie(userInfo.getUserId(), false);
61
				createUserCookie(userInfo.getUserId(), false);
-
 
62
			}
69
		}
63
		}
70
	
64
	
71
		if (action instanceof UserAware) {
65
		if (action instanceof UserAware) {
72
        	UserAware sessionAction = (UserAware) action;
66
        	UserAware sessionAction = (UserAware) action;
73
        	sessionAction.setSession(session);
67
        	sessionAction.setSession(session);
Line 77... Line 71...
77
        }
71
        }
78
 
72
 
79
		return invocation.invoke();
73
		return invocation.invoke();
80
	}
74
	}
81
	
75
	
-
 
76
	
82
	private void createCookiesMap(HttpServletRequest request) {
77
	private void createCookiesMap(HttpServletRequest request) {
83
		cookiesMap  = new HashMap<String, Cookie>();
78
		cookiesMap  = new HashMap<String, Cookie>();
84
		Cookie[] cookies = request.getCookies();
79
		Cookie[] cookies = request.getCookies();
85
		// This check is necessary for the first request when no cookies are
80
		// This check is necessary for the first request when no cookies are
86
		// sent.
81
		// sent.
Line 101... Line 96...
101
			cookiesMap.put("uid", userCookie);
96
			cookiesMap.put("uid", userCookie);
102
			HttpServletResponse response = ServletActionContext.getResponse();
97
			HttpServletResponse response = ServletActionContext.getResponse();
103
	        response.addCookie(userCookie);
98
	        response.addCookie(userCookie);
104
		}
99
		}
105
	}
100
	}
-
 
101
 
106
	
102
	
107
	private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session) {
103
	private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session) {
108
		userCookie = (Cookie) cookiesMap.get("uid");
104
		userCookie = (Cookie) cookiesMap.get("uid");
109
		UserSessionInfo userInfo = null;
105
		UserSessionInfo userInfo = null;
110
		if(userCookie != null){
106
		if(userCookie != null){
Line 119... Line 115...
119
					log.error("The UID cookie contains an unparseable userID");
115
					log.error("The UID cookie contains an unparseable userID");
120
				}
116
				}
121
			}
117
			}
122
		}
118
		}
123
		else{
119
		else{
124
			userInfo = new UserSessionInfo(session.getId());
120
			userInfo = new UserSessionInfo();
125
			session.setAttribute(USER_INFO, userInfo);
121
			session.setAttribute(USER_INFO, userInfo);
126
			log.info("Invalid session without user cookie.");
122
			log.info("Invalid session without user cookie.");
127
			createUserCookie(userInfo.getUserId(), true);
123
			//createUserCookie(userInfo.getUserId(), true);
128
		}
124
		}
129
		return userInfo;
125
		return userInfo;
130
	}
126
	}
131
}
127
}
132
128