middleware

package
v0.0.0-...-4f392d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWT = func(ctx *context.Context) {
	var code int
	var data interface{}
	var token string

	code = e.SUCCESS
	token = ctx.Request.Header.Get("X-Token")
	if token == "" {
		code = e.INVALID_PARAMS
	} else {
		claims, err := utils.ParseToken(token)
		if err != nil {
			code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
		} else if time.Now().Unix() > claims.ExpiresAt {
			code = e.ERROR_AUTH_CHECK_TOKEN_TIMEOUT
		}
	}
	if code != e.SUCCESS {
		errorInfo := auxpi.RespJson{
			Code: code,
			Msg:  e.GetMsg(code),
			Data: data,
		}
		info, _ := errorInfo.MarshalJSON()
		ctx.Output.Header("Content-Type", "application/json; charset=UTF-8")
		ctx.ResponseWriter.Write(info)
		return
	}
}
View Source
var XsrfError = func(ctx *context.Context) {
	resp := &auxpi.RespJson{}
	code := e.ERROR_ACCESS_DENIED
	_xsrf := ctx.Request.Form.Get("_xsrf")
	if _xsrf != getXSRFToken(beego.BConfig.WebConfig.XSRFKey, int64(beego.BConfig.WebConfig.XSRFExpire)) {
		resp.Code = code
		resp.Msg = e.GetMsg(code)
		resp.Data = ""
	}
	ctx.Output.Header("Content-Type", "application/json; charset=UTF-8")
	info, _ := resp.MarshalJSON()
	ctx.ResponseWriter.Write(info)
	return
}

自定义 CSRF 错误码返回

Functions

func GetSecureCookie

func GetSecureCookie(Secret, key string) (string, bool)

GetSecureCookie Get secure cookie from request by a given key.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL