scala - Lift Authentication -
i want create authentication route lift application.
- create route, instance
www.myapp.com/user/login - i not using lift forms/templating. forms rendered in js.
- send post request email , password.
- call lift authentication when post request received.
- 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
Post a Comment