github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/api4/handlers.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"github.com/mattermost/mattermost-server/web"
    10  )
    11  
    12  type Context = web.Context
    13  
    14  func (api *API) ApiHandler(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
    15  	return &web.Handler{
    16  		App:            api.App,
    17  		HandleFunc:     h,
    18  		RequireSession: false,
    19  		TrustRequester: false,
    20  		RequireMfa:     false,
    21  		IsStatic:       false,
    22  	}
    23  }
    24  
    25  func (api *API) ApiSessionRequired(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
    26  	return &web.Handler{
    27  		App:            api.App,
    28  		HandleFunc:     h,
    29  		RequireSession: true,
    30  		TrustRequester: false,
    31  		RequireMfa:     true,
    32  		IsStatic:       false,
    33  	}
    34  }
    35  
    36  func (api *API) ApiSessionRequiredMfa(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
    37  	return &web.Handler{
    38  		App:            api.App,
    39  		HandleFunc:     h,
    40  		RequireSession: true,
    41  		TrustRequester: false,
    42  		RequireMfa:     false,
    43  		IsStatic:       false,
    44  	}
    45  }
    46  
    47  func (api *API) ApiHandlerTrustRequester(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
    48  	return &web.Handler{
    49  		App:            api.App,
    50  		HandleFunc:     h,
    51  		RequireSession: false,
    52  		TrustRequester: true,
    53  		RequireMfa:     false,
    54  		IsStatic:       false,
    55  	}
    56  }
    57  
    58  func (api *API) ApiSessionRequiredTrustRequester(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
    59  	return &web.Handler{
    60  		App:            api.App,
    61  		HandleFunc:     h,
    62  		RequireSession: true,
    63  		TrustRequester: true,
    64  		RequireMfa:     true,
    65  		IsStatic:       false,
    66  	}
    67  }