Derek,

This is really helpful. That said, it doesn't answer the question I had, 
which was about not overwriting fields on a merge. Do you have any ideas 
on that?

Also, where are you putting the code below? I'd like to play around with it.

Finally, can you post your latest code for the tutorial? I think mine is 
a bit out of date now.

Thanks. I might just get this site online by the deadline this weekend. 
I'd love to be able to say I have a Lift site in production, even if I'm 
still not sure what the hell I'm doing. :-)

Chas.

Derek Chen-Becker wrote:
> What I do in my code is add a member object to the session to indicate 
> whether it's logged in:
> 
>   object currentUserObjVar extends SessionVar[Can[Member]](Empty)
>   def currentUserObj = currentUserObjVar.is
> 
>   def currentUsername = currentUserObj map {_.userId} openOr "Not logged in"
>   def currentUserId = currentUserObj map {_.id} openOr -1
> 
>   def login (member : Member) = currentUserObjVar(Full(member))
>  
>   def logout = currentUserObjVar.remove
>  
>   def isLoggedIn_? = currentUserObj.isDefined
>    
>   def isSuperuser_? = currentUserObj map {_.superuser} openOr false
> 
> I'm still doing a lot of streamlining and rework on this code so this 
> may change a bit, but in general this should be an acceptable overhead 
> on things (it doesn't take a lot of memory in your session). You do have 
> to remember, though, to merge() the member object if you want to access 
> a lazy collection or property since the "session" member is detached 
> after the initial login handling. Having the full object also means you 
> can just bind directly:
> 
>     bind("member", xhtml,
>      "id" --> Text(member.userId),
>          "firstname" --> text(member.givenName, member.givenName = _),
>          "lastname" --> text(member.surname, member.surname = _),
>          "birthday" --> text(formatDate(member.birthdate), date => 
> member.birthdate = parseDate(date,"birthday")) % ("id" -> "birthday_input"),
>          "email" --> text(member.email, member.email = _),
>          "addr1" --> text(member.address.address1, 
> member.address.address1 = _),
>          "addr2" --> text(member.address.address2, 
> member.address.address2 = _),
>          "city" --> text(member.address.city, member.address.city = _),
>          "state" --> text(member.address.state, member.address.state = _),
>          "zip" --> text(member.address.zip, member.address.zip = _),
>          "edit" --> submit("Save changes", doEdit))
> 
> Derek
> 
> On Wed, Sep 17, 2008 at 2:41 PM, Charles F. Munat <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> 
>     I'm trying to figure out the JPA demo by extending it to permit login.
> 
>     To this end, I added three attributes to the User model: validationCode,
>     passwordHash, and passwordSalt:
> 
>     class User {
>       @Id
>       @GeneratedValue{val strategy = GenerationType.AUTO}
>       var id : Long = _
> 
>       var nameLast : String = ""
>       var nameFirst : String = ""
>       var username : String = ""
> 
>       var validationCode : String = ""
>       var passwordSalt : String = ""
>       var passwordHash : String = ""
> 
>     Of course, I don't want to bind these to the add/edit form. But then
>     when I do an edit, it resets these fields to the default "". Here is the
>     UserOps code:
> 
>     def add (xhtml : NodeSeq) : NodeSeq = {
>       def doAdd () = {
>         Model.em.merge(user)
>         redirectTo("index")
>       }
> 
>       val currentId = user.id <http://user.id>
> 
>       bind(
>         "user",
>          xhtml,
>         "id" --> SHtml.hidden({user.id <http://user.id> = currentId}),
>         "nameLast" --> SHtml.text(user.nameLast, user.nameLast = _),
>         "nameFirst" --> SHtml.text(user.nameFirst, user.nameFirst = _),
>         "username" --> SHtml.text(user.username, user.username = _),
>         "save" --> SHtml.submit(?("Save"), doAdd)
>       )
>     }
> 
>     How do I prevent values in these fields from being reset on an update?
> 
>     Chas.
> 
> 
> 
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to