bwawok
bwawok

Reputation: 15357

Lift tracking a logged in user

I have a sitemap defined like this in Boot.scala

   def sitemap() = SiteMap(
      Menu(S ? "Home") / "index",
      Menu(S ? "Login") / "login",
      Menu(S ? "Do Logged in Stuff") / "loggedinstuff"  >> If( () => loggedInUser.is != Empty, "You must be logged in") )

Also I have a loggedInUser defined in Boot.scala like this

object loggedInUser extends SessionVar[Box[String]](Empty)

When I have a user log in, I want them to change my loggedInUser to be the username that they successfully logged in as.

Upvotes: 5

Views: 442

Answers (1)

bwawok
bwawok

Reputation: 15357

I was able to get it to work by doing like here

Scala and Lift and SessionVar that loses it contents

Made this object

object SessionState {

   object loggedInUserName extends SessionVar[Box[String]](Empty)
}

and then did

SessionState.loggedInUserName(Full(username))

Upvotes: 1

Related Questions