Subversion Repositories SmartDukaan

Rev

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

Rev 1044 Rev 1354
Line 36... Line 36...
36
        
36
        
37
        HttpServletRequest request = ServletActionContext.getRequest();
37
        HttpServletRequest request = ServletActionContext.getRequest();
38
        HttpSession session = request.getSession(); // Get the existing session or create a new one
38
        HttpSession session = request.getSession(); // Get the existing session or create a new one
39
        
39
        
40
        //getCookiesMap(request);
40
        //getCookiesMap(request);
41
		String requestedSessionId = request.getRequestedSessionId();
-
 
42
		
-
 
43
		UserSessionInfo userInfo = null;
-
 
44
		createCookiesMap(request);
41
		createCookiesMap(request);
45
		
42
		
46
		// Check if this is a brand new request with no prior cookies set; OR
-
 
47
		// If the request is for an active session.
43
		// If the request is for an active session.
48
		if(requestedSessionId == null || request.isRequestedSessionIdValid()){
-
 
49
			log.info("Request received for valid session: " + requestedSessionId);
-
 
50
			// Set the userinfo and the uid cookie if they're not already set.
-
 
51
			userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
44
		UserSessionInfo userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
52
			if(userInfo == null || userInfo.getUserId() == -1) {
-
 
53
				userInfo = new UserSessionInfo(session.getId());
-
 
54
				session.setAttribute(USER_INFO, userInfo);
-
 
55
			}
45
		
56
			createUserCookie(userInfo.getUserId(), false);
46
		// Set the userinfo and the uid cookie if they're not already set.
57
		} else {
47
		if (userInfo == null) {
58
			log.info("Request received for invalid session: " + requestedSessionId);
-
 
59
			// If the requested session is inactive, do the following:
-
 
60
			// 1. Retrieve the user for the requested session from the user cookie
-
 
61
			// 2. Add the retrieved user to the newly created session above.
-
 
62
			// 3. Update the uid cookie to ensure that a valid user is set in the session
-
 
63
			userInfo = createAndGetSessionFromUIDCookie(session);
48
			userInfo = createAndGetSessionFromUIDCookie(session);
64
			session.setAttribute(USER_INFO, userInfo);
49
			session.setAttribute(USER_INFO, userInfo);
65
			createUserCookie(userInfo.getUserId(), true);
-
 
66
		}
50
		}
-
 
51
		else {
-
 
52
			// Update user cookie in case of new registration and login.
-
 
53
		    createUserCookie(userInfo.getUserId(), false);
-
 
54
		}
-
 
55
	
67
		if (action instanceof UserAware) {
56
		if (action instanceof UserAware) {
68
        	UserAware sessionAction = (UserAware) action;
57
        	UserAware sessionAction = (UserAware) action;
69
        	sessionAction.setSession(session);
58
        	sessionAction.setSession(session);
70
        	sessionAction.setUserSessionInfo(userInfo);
59
        	sessionAction.setUserSessionInfo(userInfo);
71
        	sessionAction.setCookiesMap(cookiesMap);
60
        	sessionAction.setCookiesMap(cookiesMap);
Line 118... Line 107...
118
		}
107
		}
119
		else{
108
		else{
120
			userInfo = new UserSessionInfo(session.getId());
109
			userInfo = new UserSessionInfo(session.getId());
121
			session.setAttribute(USER_INFO, userInfo);
110
			session.setAttribute(USER_INFO, userInfo);
122
			log.info("Invalid session without user cookie.");
111
			log.info("Invalid session without user cookie.");
-
 
112
			createUserCookie(userInfo.getUserId(), true);
123
		}
113
		}
124
		return userInfo;
114
		return userInfo;
125
	}
115
	}
126
}
116
}
127
117