Forked from nraychaudhuri/Play2SlickBridge.scala
Last active
September 17, 2015 11:08
-
-
Save Bunyod/c84d7cac0528594d050b to your computer and use it in GitHub Desktop.
Play2-Auth and Slick together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Trait that bridges between slick and Play2-auth. Just mixin with controllers | |
trait Auth2SlickBridge { | |
self: StackableController => | |
def AuthAction[A](p: BodyParser[A], params: AttributeKey[_]*)(f: RequestWithAttributes[A] => Action[A]): Action[A] = { | |
AsyncStack(p, params:_*) { implicit rs => | |
f(rs).apply(rs) | |
} | |
} | |
def AuthAction(params: AttributeKey[_]*)(f: RequestWithAttributes[AnyContent] => Action[AnyContent]): Action[AnyContent] = { | |
AsyncStack(params:_*) { implicit rs => | |
f(rs).apply(rs) | |
} | |
} | |
} | |
//exmaple usage | |
object Message extends Controller with AuthElement with Auth2SlickBridge with AuthConfigImpl { | |
def main = AuthAction(AuthorityKey -> "user") { implicit play2AuthRequest => | |
DBAction { implicit slickRequest => | |
Computers.findById(1L).map { computer => | |
Ok(html.editForm(1L, Application.computerForm.fill(computer), Companies.options)) | |
}.getOrElse(NotFound) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment