Authentication process issue

58 views
Skip to first unread message

Uros Nedic

unread,
Feb 12, 2012, 12:37:46 PM2/12/12
to lif...@googlegroups.com
Now I have issue with authentication mechanism. I have entered the following code:

package code 
package snippet 

import net.liftweb.http._
import scala.xml.{NodeSeq, Text}
import net.liftweb.util._
import net.liftweb.common._
import code.lib._
import Helpers._
import code.model.User

class Authentication {
  var user: User = new User
  var email: String = _ 
  var password: String = _ 

  def authform(xhtml: NodeSeq): NodeSeq = { 
    bind("auth", xhtml, 
      "email" --> S.text(S.param("email").openOr(""), email = _) % 
("size" -> "10") % ("id" -> "email"), 
      "password" --> S.password("", password = _) % ("size" -> "10") % 
("id" -> "password"), 
      "submit" --> S.submit(S.?("Send"), ignore => authenticate) 
    ) 
  } 

  def authenticate = { 
    User.find(By(User.email, email)) match { 
      case Full(dbuser) if (dbuser.password.match_?(password)) => User.logUserIn(dbuser) 
      case Full(dbuser) => error("wrong password") 
      case Empty => notice("sending verification mail") 
    } 
  } 


and as a result got:

[info]   Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[error] C:\Users\WYG\Desktop\lift_basic\src\main\scala\code\snippet\Authentication.scala:19: value t
ext is not a member of object net.liftweb.http.S
[error]       "email" --> S.text(S.param("email").openOr(""), email = _) %
[error]                     ^
[error] C:\Users\WYG\Desktop\lift_basic\src\main\scala\code\snippet\Authentication.scala:28: not fou
nd: value By
[error]     User.find(By(User.email, email)) match {
[error]               ^
[error] C:\Users\WYG\Desktop\lift_basic\src\main\scala\code\snippet\Authentication.scala:29: value p
assword is not a member of Any
[error]       case Full(dbuser) if (dbuser.password.match_?(password)) => User.logUserIn(dbuser)
[error]                                    ^
[error] C:\Users\WYG\Desktop\lift_basic\src\main\scala\code\snippet\Authentication.scala:29: type mi
smatch;
[error]  found   : Any
[error]  required: code.model.User.TheUserType
[error]       case Full(dbuser) if (dbuser.password.match_?(password)) => User.logUserIn(dbuser)
[error]                                                                                  ^
[error] C:\Users\WYG\Desktop\lift_basic\src\main\scala\code\snippet\Authentication.scala:31: not fou
nd: value notice
[error]       case Empty => notice("sending verification mail")
[error]                     ^
[error] 5 errors found
[info] == compile ==
[info]
[info] == copy-resources ==
[info] == copy-resources ==
[error] Error running compile: Compilation failed
[info]

Any hint what I'm doing wrong and how to fix it?

Thanks,
Uros

Aditya Vishwakarma

unread,
Feb 12, 2012, 12:46:16 PM2/12/12
to lif...@googlegroups.com
For compiler errors :
  1. text is in SHtml . S stands for Session while SHtml generates Html codes
  2. By exists in lift.mapper which you haven't included
  3.  3 and 4 should go away if you have mapper imported
  4. notice exists in S. So do S.notice.
That should solve the compiler errors.
Aditya Vishwakarma




--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Stefan Bradl

unread,
Feb 12, 2012, 12:48:03 PM2/12/12
to lif...@googlegroups.com
At first you have to use SHtml in some cases (not S)

To use "By" you have to import net.liftweb.mapper._

notice is a method from S (use S.notice)

Uros Nedic

unread,
Feb 12, 2012, 1:54:25 PM2/12/12
to lif...@googlegroups.com
I modifed the code according to your instructions. Now I have another weird issue.
My rendered html page shows only email field but not password neither button.
Snippet follows:

<p class="lift:surround?with=frontpage;at=content"> 
<lift:Authentication.authform form="POST"> 
  <label for="email">Email:</label> 
  <auth:email /> 
  <br/> 
  <label for="password">Password:</label> 
  <auth:password /> 
  <br/> 
  <auth:submit/> 
</lift:Authentication.authform> 
</p>

Modified Authentication class is:

class Authentication {
  var user: User = new User
  var email: String = _ 
  var password: String = _ 

  def authform(xhtml: NodeSeq): NodeSeq = { 
    bind("auth", xhtml, 
      "email" -> SHtml.text(S.param("email").openOr(""), email = _) % ("size" -> "10") % ("id" -> "email"), 
      "password" -> SHtml.password("", password = _) % ("size" -> "10") % ("id" -> "password")
      "submit" -> SHtml.submit(S.?("Send"), () => authenticate)  
    )
  } 

  def authenticate = { 
    User.find(By(User.email, email)) match { 
      case Full(dbuser) if (dbuser.password.match_?(password)) => User.logUserIn(dbuser) 
      case Full(dbuser) => S.error("wrong password") 
      case Empty => S.notice("sending verification mail") 
    } 
  } 
}

Uros

Uros Nedic

unread,
Feb 13, 2012, 6:12:26 AM2/13/12
to lif...@googlegroups.com
After whole day of analyzing my code I still do not have idea WHY Lift doesn't want to render password field
and submit button?

Any hint would be more than welcomed!

Thanks in advance,
Uros

Uros Nedic

unread,
Feb 13, 2012, 7:16:50 AM2/13/12
to lif...@googlegroups.com
If found where I made mistake! In snippet code I had something like

<p class="lift:...">
</p>

Instead of <p> tag, I have used <div> tag as has been suggested in
sticky post regarding HTML5 vs XHTML.

Regards,
Uros

David Pollak

unread,
Feb 13, 2012, 9:36:21 AM2/13/12
to lif...@googlegroups.com
If you're using Html5, then <foo:password/> will be ignored by the Html5 parser.  Please see http://groups.google.com/group/liftweb/browse_thread/thread/1fec5ed6e44b5b57

Please also post example code (see https://www.assembla.com/wiki/show/liftweb/Posting_example_code ) if you have questions that aren't answered the first few go-arounds.  Issues that are not obvious if you copy/paste a little code into the message are often obvious if you have runnable code.
 
Regards,
Uros

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Uros Nedic

unread,
Feb 18, 2012, 10:42:13 AM2/18/12
to lif...@googlegroups.com
Thank you for reply. I will read carefully procedures how to post longer and more complicated code.
I thought code I already post was a rather simple one. In a few days I plan to enter into the world of
Lift Actors and see how they differ from Scala Actors. That would be rather tough I believe.

Regards,
Uros

David Pollak

unread,
Feb 18, 2012, 12:15:45 PM2/18/12
to lif...@googlegroups.com
Lift actors mostly differ in quality of implementation, but not concepts from Scala actors.
--
Reply all
Reply to author
Forward
0 new messages