Extended sessions

47 views
Skip to first unread message

David Pollak

unread,
Jul 29, 2008, 7:14:56 PM7/29/08
to liftweb
Folks,

There's now a way to associate an extended session (one that lasts longer than the server session) such that each time a user comes back to the site, they are automatically logged in:

object ExtSession extends ExtSession with MetaProtoExtendedSession[ExtSession] {
  override def dbTableName = "ext_session" // define the DB table name
 
  def logUserIdIn(uid: String): Unit = User.logUserIdIn(uid)

  def recoverUserId: Can[String] = User.currentUserId
 
  type UserType = User
}

class ExtSession extends ProtoExtendedSession[ExtSession] {
  def getSingleton = ExtSession // what's the "meta" server
 
}

class Boot {
  def boot {
   
    Schemifier.schemify(true, Log.infoF _, User, ExtSession)
   
    S.addAround(ExtSession.requestLoans)
   
  }
}

object User extends User with MetaOpenIDProtoUser[User] {

  onLogIn = ExtSession.userDidLogin _ :: onLogIn

  onLogOut =  ExtSession.userDidLogout _ :: onLogOut
}

This collection of code creates a cookie each time the user logs in.  By default, the cookie lives for 180 days.  Each time the user comes back, the user's ID is retrieved from the RDBMS.

Thanks,

David

--
lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Reply all
Reply to author
Forward
0 new messages