简体   繁体   中英

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.

  • Is this an okay way to deal with logging in users?
  • Where should I keep my loggedInUser object. Boot.scala? Somewhere else?
  • How do I update loggedInUser so that he will now work to show the "loggedinstuff" page?

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM