Custom Login

9 views
Skip to first unread message

turp1twin

unread,
Aug 6, 2009, 11:20:23 PM8/6/09
to Lift
I am new to Lift and have a "newbie" question. I have searched the
group and have not really found an answer to my question. I was hoping
for some pointers on implementing custom Login logic. I am currently
looking at the MetaMegaProtoUser code and am trying sort out what I
will need. I have no need for scaffolding, and am using an existing DB
with client access through Hibernate/JPA classes. I can sort out the
DB access, etc., I am just getting a bit overwhelmed trying to figure
what bits I need to replicate from MetaMegaProtoUser, if any. I know
it does quite a bit... Anyways, it is probably staring me right in the
face... and I am just being dense... but any pointers would be
appreciated! I am loving Scala and am really enjoying learning Lift,
really cool work guys! Cheers!


Jeff

David Pollak

unread,
Aug 6, 2009, 11:48:40 PM8/6/09
to lif...@googlegroups.com
I think you could remove the User class/object pair from the app and replace them with:

object LoginState {
  object primaryKey extends SessionVar[Box[Long]](Empty) // the primary key of the currently logged in user... change to Box[String] if the PK is a String
  object currentUser extends RequestVar[Box[YourUserClass]](primaryKey.is.flatMap(key => lookupUser(key)))

  def logUserIn(u: YourUserClass) {
    currentUser.remove()
    primaryKey.set(Full(u.getPrimaryKey))
  }

  def logUserOut() {
    currentUser.remove()
    primaryKey.remove()
    S.request.foreach(_.request.getSession.invalidate)
  }

  def loggedIn_? = primaryKey.is.isDefined
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

turp1twin

unread,
Aug 7, 2009, 2:30:15 AM8/7/09
to Lift
Thanks David! This makes sense to me. Thanks much for the support and
keep up the great work!

Jeff
> Beginning Scalahttp://www.apress.com/book/view/1430219890
Reply all
Reply to author
Forward
0 new messages