DBAction与IsAuthenticated一起使用:

时间:2014-09-10 13:00:27

标签: scala playframework slick

我有以下代码,但它抱怨:

找不到参数会话的隐含值:play.api.db.slick.Config.driver.simple.Session

我该如何解决?

trait Secured extends Controller {

  /**
   * Retrieve the connected user id.
   */
  def username(request: RequestHeader) = request.session.get("email")

  /**
   * Redirect to login if the use in not authorized.
   */
  def onUnauthorized(request: RequestHeader): Result

  def IsAuthenticated(f: => String => Request[AnyContent] => Result) =
    Security.Authenticated(username, onUnauthorized) { user =>
      DBAction(request => f(user)(request))
    }
}

我有以下代码:

object Application extends Controller with Secured { 
....
  def list(modelName: String, page: Int, orderBy: Int, filter: String) = IsAuthenticated{username=> implicit rs =>
    Ok(html.list(
      Model.byName(modelName),
      page,
      orderBy, filter
    ))
  }

1 个答案:

答案 0 :(得分:0)

您必须在控制器中导入光滑的会话

import play.api.db.slick.Config.driver.simple.Session
...
object Application extends Controller with Secured { 
...