另外,如果不满足if语句,我如何向用户提供所请求的页面?
这是我到目前为止所做的:
object AuthFilter extends EssentialFilter {
def apply(next: EssentialAction) = new EssentialAction {
def apply(request: RequestHeader) = {
if(request.session.get("auth").isEmpty && !request.path.contains("/login")){
//redirect to login page.
} else {
//show requested page.
next(request) //is this correct?
}
}
}
}
答案 0 :(得分:1)
为什么不延伸Filter
而不是EssentialFilter
?
object AuthFilter extends Filter {
def apply(next: (RequestHeader) => Future[SimpleResult])(request: RequestHeader): Future[SimpleResult] = {
if(request.session.get("auth").isEmpty && !request.path.contains("/login")){
Future.successful(Ok(views.html.yourLoginPage()))
} else {
next(request)
}
}
}