Best way to create a login/logout form in Scala using Lift

隐身守侯 提交于 2019-12-04 07:06:43
thoredge
  1. This shows how to force use of SSL, you will typically use that for the login form page menu: Lift filter to force ssl
  2. A session variable is typically best way to keep session information
  3. ProtoUser (you can use Lifty (http://lifty.github.com/) to setup a project with login as an example)

Lift provides a scaffolding framework for these usecases. You want to have a look at the source code of net.liftweb.proto.ProtoUser. Especially login() and loginXhtml.

The basic examples of Lift do it the following way:

  1. Create an own mapped user class that uses all the nasty lift code

    package yourcompany.model
    
    import net.liftweb.mapper._
    import net.liftweb.util._
    import net.liftweb.common._
    
    class User extends MegaProtoUser[User] { 
      // your code, mostly overrides
    
    }
    
    object User extends User with MetaMegaProtoUser[User] {
      override def dbTableName = "users"
      // other database related code
    }
    
  2. In your Boot after you defined your sitemap, do the following:

    // do not forget to import your user
    def sitemap() = Sitemap(Menu("Home") / "index" >> User.AddUserMenusAfter)
    
    // now comes the magic
    LiftRules.setSiteMap(User.sitemapMutator(sitemap()))
    

This will include many links on your page, all gathered under /user_mgt e.g. sign_up, login, lost_password. For me this is a great base to work from. You can override almost all the things that happen in ProtoUser, or just copy the nice bits and implement everything yourself.

Also if someone has additional docs on that, it will be very helpful. At the moment I try to figure out the most part using the sources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!