Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 254
bwawok Avatar asked Nov 14 '22 04:11

bwawok


1 Answers

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))
like image 152
bwawok Avatar answered Dec 08 '22 01:12

bwawok