Subversion Repositories SmartDukaan

Rev

Rev 419 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 419 Rev 424
Line 39... Line 39...
39
    protected HttpServletResponse response;
39
    protected HttpServletResponse response;
40
    protected HttpServletRequest request;
40
    protected HttpServletRequest request;
41
    protected HttpSession session;
41
    protected HttpSession session;
42
    
42
    
43
    UserSessionInfo userinfo = null;
43
    UserSessionInfo userinfo = null;
44
//    public boolean isLoggedIn = false;
-
 
45
//    public boolean isSessionId = true;
-
 
46
//    public long userId = 0;
-
 
47
    //private String email = "";
-
 
48
    
44
    
49
    Cookie tempCookie = null;
45
    Cookie tempCookie = null;
50
    
46
    
51
	private static Log log = LogFactory.getLog(BaseController.class);
47
	private static Log log = LogFactory.getLog(BaseController.class);
52
	
48
	
53
	public BaseController() {
49
	public BaseController() {
54
		//setSessionAndCookies();
-
 
55
		// TODO Auto-generated constructor stub
-
 
56
	}
50
	}
57
	public Map getCookiesMap() {
51
	public Map getCookiesMap() {
58
		return cookiesMap;
52
		return cookiesMap;
59
	}
53
	}
60
	
54
	
Line 68... Line 62...
68
	{
62
	{
69
		this.response = response;
63
		this.response = response;
70
		if(tempCookie != null){
64
		if(tempCookie != null){
71
			this.response.addCookie(tempCookie);
65
			this.response.addCookie(tempCookie);
72
		}
66
		}
73
		//removeSessionOnLogout();
-
 
74
	}
67
	}
75
	
68
	
76
	@Override
69
	@Override
77
	public void setServletRequest(HttpServletRequest request){
70
	public void setServletRequest(HttpServletRequest request){
78
		this.request = request;
71
		this.request = request;
79
		this.session = request.getSession();
72
		this.session = request.getSession();
80
		//setSessionAndCookies();
-
 
81
		setUserSessionInfo();
73
		setUserSessionInfo();
82
	}
74
	}
83
	
75
	
84
 
-
 
85
	
-
 
86
	public void removeUserSessionInfo(){
76
	public void removeUserSessionInfo(){
87
		if(this.session.getAttribute("userinfo") != null ){
77
		if(this.session.getAttribute("userinfo") != null ){
88
			this.session.removeAttribute("userinfo");
78
			this.session.removeAttribute("userinfo");
89
		}
79
		}
90
	}
80
	}
Line 154... Line 144...
154
		    	tempCookie = cookie1;
144
		    	tempCookie = cookie1;
155
			}
145
			}
156
		}
146
		}
157
	}
147
	}
158
 
148
 
-
 
149
	public String getEmail(){
-
 
150
		return userinfo.getEmail();
-
 
151
	}
-
 
152
 
-
 
153
	public String getNameOfUser(){
-
 
154
		return userinfo.getNameOfUser();
-
 
155
	}
159
 
156
 
-
 
157
}
-
 
158
	/*
160
	
159
	
161
//	public String getEmail(){
160
//	public String getEmail(){
162
//		if(this.session.getAttribute("email") != null){
161
//		if(this.session.getAttribute("email") != null){
163
//			return this.session.getAttribute("email").toString();
162
//			return this.session.getAttribute("email").toString();
164
//		}else{
163
//		}else{
Line 199... Line 198...
199
 
198
 
200
	}
199
	}
201
	
200
	
202
	
201
	
203
	public void setSessionAndCookies(){
202
	public void setSessionAndCookies(){
204
		/*Following steps will be executed on each of the requests
203
		 *Following steps will be executed on each of the requests
205
		 * 		Check Session: 
204
		 * 		Check Session: 
206
		 * 			IF user is loggedin 
205
		 * 			IF user is loggedin 
207
		 * 				- OK. Nothing to do. Allow access to the resources
206
		 * 				- OK. Nothing to do. Allow access to the resources
208
		 * 			ELSE check cookies 
207
		 * 			ELSE check cookies 
209
		 *  			IF UserID is set
208
		 *  			IF UserID is set
Line 217... Line 216...
217
		 *  					OK....set session id in session also
216
		 *  					OK....set session id in session also
218
		 *  				ELSE Create SessionID and Set SessionID in cookies and Session
217
		 *  				ELSE Create SessionID and Set SessionID in cookies and Session
219
		 * 			ELSE IF SessionID is set in session
218
		 * 			ELSE IF SessionID is set in session
220
		 * 				- OK.
219
		 * 				- OK.
221
		 *  	
220
		 *  	
222
		 */
221
		 *
223
		
222
		
224
		String loggedIn = null;
223
		String loggedIn = null;
225
		String userId = null;
224
		String userId = null;
226
		String isSessionId = null;
225
		String isSessionId = null;
227
		
226
		
Line 368... Line 367...
368
			else{
367
			else{
369
				/* 	may be something different can be done as commented
368
				/* 	may be something different can be done as commented
370
				 *	this.session.setAttribute("userid", userId+"");
369
				 *	this.session.setAttribute("userid", userId+"");
371
				 *	this.session.setAttribute("loggedin", "false");
370
				 *	this.session.setAttribute("loggedin", "false");
372
				 *	this.session.setAttribute("issessionid", "false");		
371
				 *	this.session.setAttribute("issessionid", "false");		
373
				 */
372
				 *
374
				if(!foundSessionIdCookie){
373
				if(!foundSessionIdCookie){
375
					sessionId = getNewUserSessionId();
374
					sessionId = getNewUserSessionId();
376
				}
375
				}
377
				
376
				
378
				this.session.setAttribute("userid", sessionId+"");
377
				this.session.setAttribute("userid", sessionId+"");
Line 415... Line 414...
415
 
414
 
416
}
415
}
417
 
416
 
418
 
417
 
419
 
418
 
420
	/*
-
 
421
			}	
419
			}	
422
		}
420
		}
423
	
421
	
424
	else if(getCookiesMap() != null){
422
	else if(getCookiesMap() != null){
425
			Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");
423
			Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");