2014-09-16 7 views
2

액션이 있는데 https를 강제 실행하겠습니다.작업에 매개 변수를 추가 할 수 있습니까?

사용자 지정 작업에 매개 변수를 추가하려면 어떻게해야합니까? 그래서 내 컨트롤러

import play.api.mvc._ 

def onlyHttps[A](action: Action[A]) = Action.async(action.parser) { request => 
    request.headers.get("X-Forwarded-Proto").collect { 
    case "https" => action(request) 
    } getOrElse { 
    Future.successful(Forbidden("Only HTTPS requests allowed")) 
    } 
} 

:

def index = onlyHttps(false) { 
    // .. 
} 

또 다른 영역 나는 현재 로그인 한 사용자 권한의 특정 수준을 가지고 있는지 확인하려면, 그래서 권한 유형을 전달하려는 것입니다 (들) 내 사용자 지정 작업에 대한 매개 변수로.

답변

2

간단히 another parameter list을 추가

def onlyHttps[A](limitToHttps: Boolean)(action: Action[A]) = /* 
    Your implementation here. You can access `limitToHttps` here. */ 
관련 문제