compose slick dbaction with authenticated action

有些话、适合烂在心里 提交于 2019-12-21 21:49:36

问题


I have my custom authenticated action that is like

def Authenticated(rights: String*) = new ActionBuilder[MyAuthenticatedRequest] {
  ***
}

In my controller I use this action to check the user has the right to view the page

def password = Authenticated(UserRights.USER) { implicit request: MyAuthenticatedRequest[_] =>
  Users.findById(request.account.id) match {
    case Some(user) => Ok(views.html.settings.password(frontUser, user))
    case _ => NotFound
  }
}

My oject Users uses slick to retrieve the user in the database

def findById(id: Long)(implicit s: Session): Option[User] = users.where(_.id === id).firstOption

In my controller I have an error

could not find implicit value for parameter s: play.api.db.slick.Config.driver.simple.Session

This is due to the fact that I have to open a session in my controller before querying the database.

I would like to use DBAction that is provided by play-slick and compose it with my authenticated action but I have some problems understanding how action composition works

来源:https://stackoverflow.com/questions/22710592/compose-slick-dbaction-with-authenticated-action

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