Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created June 16, 2012 16:34
Show Gist options
  • Save andypetrella/2941878 to your computer and use it in GitHub Desktop.
Save andypetrella/2941878 to your computer and use it in GitHub Desktop.
Interceptors typesafe'ly combined
val securedByUserName = Intercept(
r => Cache.getAs[String]("username").toSuccess(NonEmptyList("No username")),
(err, v:Failure[NonEmptyList[String], String]) => Unauthorized(v.e.list.mkString("\n"))
)
val securedByUserId = Intercept(
r => Cache.getAs[String]("userid").map(_.toInt).toSuccess(NonEmptyList("No userid")),
(err, v:Failure[NonEmptyList[String], Int]) => Unauthorized(v.e.list.mkString("\n"))
)
def securedAction = (securedByUserName ~::~ securedByUserId).apply { case (username:String) :: (userId:Int) :: HNil =>
Action {
/*Yeepee : get some stuff in the database using the id*/
Ok("Welcome Nb. " + userId + "\naka : " + username + "")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment