User model

2 views
Skip to first unread message

ishaaq

unread,
May 3, 2009, 6:48:02 AM5/3/09
to Lift
Hi all,
I've just started playing with Lift so forgive me if this question
seems a bit naive - that would be because I am a newbie :)

I am trying to build a webapp with user authentication. However, I
don't want to use ProtoUser because I want to key it by the userid -
which is a unique String not a Long.

Since the doco is a bit sparse I am at a bit of a loss at how to get
user authentication done without using ProtoUser. Any pointers would
be appreciated.

Thanks,
Ishaaq

David Pollak

unread,
May 3, 2009, 9:21:00 AM5/3/09
to lif...@googlegroups.com
There's no such thing as user authentication built into Lift.  Lift has no concept of a User.  All code for authentication is built on top of simple Lift constructs.

Lift has a concept called a SessionVar which allows you to put a type-safe value into a place that's session-specific.  In MegaProtoUser:

  private object curUserId extends SessionVar[Box[String]](Empty)

  def currentUserId: Box[String] = curUserId.is

  private object curUser extends RequestVar[Box[ModelType]](currentUserId.flatMap(id => getSingleton.find(id)))


  def currentUser: Box[ModelType] = curUser.is

So, the curUserId SessionVar stores the currently logged in User's id (as a String).  The curUser RequestVar is the current User object, but calculated on a request-by-request basis.

This is all you need for your own authentication mechanism.

Thanks,

David
 

Thanks,
Ishaaq





--
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
Reply all
Reply to author
Forward
0 new messages