I've been working on some code to automate login; however, I still haven't 
gotten it to work the way I want. My problem seems to be related to adding a 
persistent cookie (one that will last through multiple sessions) during the 
execution of an action.

I've put the cookie check (check to see if the user has a cookie set for 
auto-login) in SessionValidator. In my case, I modified a copy of 
TemplateSessionValidator that I put in my package classpath. Witin the 
conditional "if (data.getUser == null)" block, I get all the cookies and 
check to see if one of them is an auto-login cookie. If so, put he 
username/password in the RunData's parameter list, and:

ActionLoader.getInstance().exec(data, 
TurbineResources.getString("action.login"));

Then, if the User object within the RunData is not logged in, set the user 
to the anonymous user (this is in case the cookie didn't sucessfully log the 
user in). Also, if no cookies for auto-login where found, again set the 
anonymous user.

Anyway, this seems to work okay. I did some testing by adding a cookie with 
a correct username/password for a value and a MaxAge of (60*60*24*365) in 
the default template, so the cookie would be set immediately upon accessing 
the site. Then I hit the site and closed my browser and hit the site again 
(this time the cookie was set...) and I was already logged in. This all 
seems great so far.

To continue the test, I change the code I used to set the cookie so set the 
MaxAge to (0). Again, I hit the site, and the new cookie was set (which 
basically deleted the previous cookie) and I closed the browser again. Upon 
opening it once more, I was logged out. Again, everything seems great...

My next step was to lose the cookie in the default template, and put the 
code in the LoginUser action where I had planned for it to go. I added a 
"remember me" checkbox to the login form. Then, I literatally cut & pasted 
my cookie code from the default template to the LoginUser action and put it 
within a conditional check to see if the user checked the "remember me" 
checkbox, and set the MaxAge back to (60*60*24*365).

I figured this would be the easy part. The only time a cookie would be set 
is when a user logs in with the "remember me" checkbox checked. I used 
navigator and set it to warn me about cookies, then I hit the site. When I 
hit the site, I saw the session cookie warning first (name=JSESSIONID) and 
let it set the cookie. Then I navigated the site for a bit and tried to 
login. Sure enough, it gave me a warning with the correct name/value/maxage 
and I let it set. Unfortunately, after closing the browser and hitting the 
site again, I wasn't logged in. I put plently of debug code in and realized 
that the server was not seeing a cookie when the browser revisited the site.

I decided to put the cookie code back into default template's class and try 
again, everything worked fine...

So it seems that the only difference between my code working and not working 
is whether the code is executed during an action or a screen. When the 
cookie set code is executed during an action, it only seems to persist until 
the next request, yet when it is executed during a screen, it lasts until 
the MaxAge (like I was hoping...). Can anyone tell me what is going on? or 
how to fix this? I'd be happy to provide any other information necessary...
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to