scala - Lift Authentication -


i want create authentication route lift application.

  1. create route, instance www.myapp.com/user/login
  2. i not using lift forms/templating. forms rendered in js.
  3. send post request email , password.
  4. call lift authentication when post request received.
  5. use users.login(email, password) method validate credentials.

q: how tell lift authenticate credentials incoming via /user/login?

this overly simplistic, allow create url can post to. json extraction not safe, should give idea of how might work.

in boot.scala

liftrules.dispatch.append(new resthelper{   serve {     case jsonpost("user" :: "login" :: nil, (json, _)) =>       //extract json json object username , password       val useremail:string = (json \ "username").extract[string]       val password = (json \ "password").extract[string]       user.login(useremail, password) match {         case full(r) =>           user.current(true)           inmemoryresponse(array(), nil, nil, 200)         case _ => forbiddenresponse       }   } }) 

in user.scala

object user {   object loggedin extends sessionvar[boolean](false) } 

then can use if(user.loggedin.get){ ... } test if user logged in anywhere. work added stateful dispatch, if use liftrules.statelessdispatch session not exist.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -