ProtoUser.autologinFunc and sessions

37 views
Skip to first unread message

Jeppe Nejsum Madsen

unread,
Feb 18, 2011, 9:51:19 AM2/18/11
to lif...@googlegroups.com
Hi,

I'm trying to use ProtoUser.autoLoginFunc to automatically log in a user when running in dev mode. So I have this:

 def testUserLogin() {
    val testUser = User.find(4)
    testUser foreach {u =>
      logUserIn(u)
      info("Auto login for %s id is %s, session=%s".format(u, currentUserId, S.session))
    }
  }
 
 autologinFunc = if (Props.devMode) Full(testUserLogin) else Empty
 
And while this works, the method is called repeatedly (4 times for each request). It logs S.session as Empty even if a session has been created, and I believe this causes the logUserIn call to not register the user id in the session var?

I think maybe the autoLoginFunc is called early, before the session is set up. Any clues as to how this can be solved?

/Jeppe

Timothy Perrett

unread,
Feb 19, 2011, 6:03:41 AM2/19/11
to lif...@googlegroups.com
Hm, i've not looked at the code, but perhaps its memoizable? Either that, or perhaps the session is being torn down explicitly to avoid session fixation. 

Cheers, Tim

Jeppe Nejsum Madsen

unread,
Feb 19, 2011, 7:12:07 AM2/19/11
to lif...@googlegroups.com
Timothy Perrett <tim...@getintheloop.eu> writes:


It is a regular SessionVar and there doesn't seem to be any explicit
session handling in the code path, but the autologinFunc seems to be
called early (when checking sitemap) which made me guess that might be
the reason...

/Jeppe

Jeppe Nejsum Madsen

unread,
Feb 28, 2011, 9:27:54 AM2/28/11
to lif...@googlegroups.com

So has anyone used autologinFunc successfully? If so please share :-)

/Jeppe

cloudy77

unread,
Mar 21, 2011, 11:12:53 AM3/21/11
to Lift
Hi Jeppe,

the following code works for me on 2.3-RC3:

if (Props.devMode) autologinFunc = Full(autoLogin)


private def autoLogin() {
println("autoLogin\n\n\n")
val u = User.findUserByUserName("du...@altus-insight.de")
if (u.isDefined) {
logUserIn(u.get)
} else {
debug("could not find dummy user for auto login. please create user
du...@altus-insight.de")
}
}


The method autoLogin is called one time. If i do not call "logUserIn"
int this method, it is called several times.


I hope, this helps,

Helmut

On Feb 28, 3:27 pm, Jeppe Nejsum Madsen <je...@ingolfs.dk> wrote:
> On Sat, Feb 19, 2011 at 1:12 PM, Jeppe Nejsum Madsen <je...@ingolfs.dk> wrote:
>

Jeppe Nejsum Madsen

unread,
Mar 21, 2011, 11:35:50 AM3/21/11
to lif...@googlegroups.com
On Mon, Mar 21, 2011 at 4:12 PM, cloudy77
<helmut....@googlemail.com> wrote:
> Hi Jeppe,
>
> the following code works for me on 2.3-RC3:
>
>        if (Props.devMode) autologinFunc = Full(autoLogin)
>
>
>        private def autoLogin() {
>                println("autoLogin\n\n\n")
>                val u = User.findUserByUserName("du...@altus-insight.de")
>                if (u.isDefined) {
>                        logUserIn(u.get)
>                } else {
>                        debug("could not find dummy user for auto login. please create user
> du...@altus-insight.de")
>                }
>        }
>
>
> The method autoLogin is called one time. If i do not call "logUserIn"
> int this method, it is called several times.
>
>
> I hope, this helps,

Thanks for the update. I forgot to send an update to the list, but I
also got it to work at some point.

Not sure if it was fixed by updating to the latest 2.3-SNAPSHOT or
removing some code in our own impl of the User class (the stuff we
made is now in ProtoUser so it was obsolete, but may have interfered
with the use of autoLogin)

/Jeppe

Reply all
Reply to author
Forward
0 new messages