我试图用其他一些操作组成一个基本的身份验证:
def findByNameSecure(username: String) = Authenticated { _ =>
val cursor: Cursor[JsObject] = persons.
find(Json.obj("userdetails.username" -> username)).
cursor[JsObject](ReadPreference.primary)
val res = cursor.collect[List]().map { persons =>
Ok(Json.toJson(persons))
} .recover {
case _ => BadRequest(Json.parse("{'error': 'failed to read from db'}"))
}
Await.result(res, 10.seconds)
}路由:
GET /secure/user/findbyname controllers.UserController.findByNameSecure(username: String)这如预期的那样起作用。令人不安的是,我使用了阻塞的Await.result。如何编写这种身份验证的异步版本?
我使用的是play 2.4。
发布于 2017-02-22 13:00:42
AuthendicatedBuilder是ActionBuilder的孩子。因此,我认为它的async方法也应该工作。
使用示例:
def findByNameSecure(username: String) = Authenticated.async { _ =>https://stackoverflow.com/questions/42386382
复制相似问题