forked from t2v/play2-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced: asynchronous support
Kazuhiro Sera edited this page Jun 13, 2013
·
6 revisions
This feature is available from 0.10-SNAPSHOT!
You can use asynchronous libraries ( for example: ReactiveMongo ) for User resolver.
trait AuthConfigImpl extends AuthConfig {
...snip
def resolveUser(id: Id): Option[User] = throw new AssertionError("dont use!")
override def resolveUserAsync(id: Id)(implicit context: ExecutionContext): Future[Option[User]] =
collection.find(BSONDocument("id" -> id)).cursor[User].headOption()
}That's it. No big deal.
AuthElement trait use the resolveUserAsync method always.
If you use old style ( that Auth trait was used ), you can use AsyncAuth instead of Auth.
trait Messages extends Controller with AsyncAuth with AuthConfigImpl {
import scala.concurrent.ExecutionContext.Implicits.global
def main = authorizedAction(NormalUser) { user => request =>
val title = "message main"
Ok(html.message.main(title))
}
def list = authorizedAction(NormalUser) { user => request =>
val title = "all messages"
Ok(html.message.list(title))
}
}Please add resolver into your Build.scala
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"