Ah, that's clever. I'll switch to that. I forget that if map works at 
all, the Can is full.

I'm not sure what the problem was. I wrote some more code to fill things 
in while waiting for a response, and now it's running beautifully. I'm 
really liking JPA. It's rocking fast and very powerful.

Chas.

Derek Chen-Becker wrote:
> Everything there looks kosher at first glance to me. SessionVars should 
> stay in the session no matter what. One thing I can think of is if 
> somehow you're losing the session. Is the session ID being stored in a 
> cookie, or as part of the URI? If it's part of the URI you may be 
> dropping it somewhere else in your code if you process the URI at all. 
> That's just a guess. Also, I would probably write the isAuthenticated 
> method as:
> 
> def isAuthenticated_? : CurrentUserId.map(true) openOr false
> 
> Derek
> 
> On Thu, Oct 16, 2008 at 5:15 PM, Charles F. Munat <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> 
>     I've got a JPA Lift site and have set up a login in which the User's id
>     is stored in a session variable thus, as shown below.
> 
>     This works just fine. The user can log in and go from page to page. But
>     after some random number of clicks, whoops! I'm suddenly no longer
>     logged in.
> 
>     Hmmm. I must be doing something wrong. I just love intermittent
>     failures.
> 
>     (My user object is a Member.)
> 
>     object CurrentUserId extends SessionVar[Can[Long]](Empty)
>     object RequestedURL extends SessionVar[Can[String]](Empty)
>     object CurrentUser extends RequestVar[Can[Member]](Empty)
> 
>     object AccessControl {
> 
>       def login(): Can[LiftResponse] = {
>         if (S.post_?) {
>           try {
>             val member: Member = Model.createNamedQuery[Member](
>               "findMemberByEmailAddress",
>               "emailAddress" ->
>                 S.param("emailAddress").openOr("")).getSingleResult()
> 
>             if (member.authenticate(S.param("password").openOr(""))) {
>                 CurrentUser(Full(member))
>                 CurrentUserId(Full(member.id <http://member.id>))
>             }
>             else
>               S.error("Go away!")
> 
>           } catch {
>             case x: NoResultException =>
>               S.error("This thing don't work.")
>             case _ => S.error("Done broke. Ouch.")
>           }
>         }
> 
>         val uri = RequestedURL.openOr("/")
>         RequestedURL(Empty)
>         Full(RedirectResponse(uri))
>       }
> 
>       def logout(): Can[LiftResponse] = {
>         CurrentUser(Empty)
>         CurrentUserId(Empty)
>         Full(RedirectResponse(S.param("path").openOr("/")))
>       }
> 
>       def isAuthenticated_?() : Boolean = CurrentUserId.is match {
>         case Empty => false
>         case Full(_) => true
>         case _ => false
>       }
> 
>     Then:
> 
>     Menu(Loc("forum", List("forum", "index"), "Forum", LocGroup("global"),
>       If(isAuthenticated_?, "Please log in to see this page.")))
> 
> 
> 
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to