base

package
v3.14.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0 Imports: 9 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilterLoginUser = func(ctx *context.Context) {
	cookieSig := ctx.GetCookie("sig")
	if cookieSig == "" {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	sessionObj := uic.ReadSessionBySig(cookieSig)
	if sessionObj == nil || int64(sessionObj.Expired) < time.Now().Unix() {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	u := uic.ReadUserById(sessionObj.Uid)
	if u == nil {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	ctx.Input.SetData("CurrentUser", u)
}
View Source
var FilterTargetTeam = func(ctx *context.Context) {
	tid := ctx.Input.Query("id")
	if tid == "" {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("id is necessary"))
		return
	}

	id, err := strconv.ParseInt(tid, 10, 64)
	if err != nil {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("id is invalid"))
		return
	}

	t := uic.ReadTeamById(id)
	if t == nil {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("no such team"))
		return
	}

	ctx.Input.SetData("TargetTeam", t)
}
View Source
var FilterTargetUser = func(ctx *context.Context) {
	userId := ctx.Input.Query("id")
	if userId == "" {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("id is necessary"))
		return
	}

	id, err := strconv.ParseInt(userId, 10, 64)
	if err != nil {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("id is invalid"))
		return
	}

	u := uic.ReadUserById(id)
	if u == nil {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("no such user"))
		return
	}

	ctx.Input.SetData("TargetUser", u)
}

Functions

This section is empty.

Types

type ApiResp

type ApiResp struct {
	Version string                 `json:"version,omitempty"`
	Method  string                 `json:"method,omitempty"`
	Status  string                 `json:"status,omitempty"`
	Error   map[string]interface{} `json:"error,omitempty"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

type BaseController

type BaseController struct {
	beego.Controller
}

func (*BaseController) AutoServeError

func (this *BaseController) AutoServeError(err error)

func (*BaseController) BasicRespGen

func (this *BaseController) BasicRespGen() (apiResp *ApiResp)

func (*BaseController) MustGetBool

func (this *BaseController) MustGetBool(key string, def bool) bool

func (*BaseController) MustGetInt

func (this *BaseController) MustGetInt(key string, def int) int

func (*BaseController) MustGetInt64

func (this *BaseController) MustGetInt64(key string, def int64) int64

func (*BaseController) MustGetString

func (this *BaseController) MustGetString(key string, def string) string

func (*BaseController) NotFound

func (this *BaseController) NotFound(body string)

func (*BaseController) ResposeError

func (this *BaseController) ResposeError(apiBasicParams *ApiResp, msg string)

func (*BaseController) ServeApiJson

func (this *BaseController) ServeApiJson(msg *ApiResp)

func (*BaseController) ServeDataJson

func (this *BaseController) ServeDataJson(data interface{})

func (*BaseController) ServeErrJson

func (this *BaseController) ServeErrJson(msg string)

func (*BaseController) ServeOKJson

func (this *BaseController) ServeOKJson()

func (*BaseController) SessionCheck

func (this *BaseController) SessionCheck() (session *uic.Session, err error)

func (*BaseController) SessionExpired

func (this *BaseController) SessionExpired()

func (*BaseController) SetPaginator

func (this *BaseController) SetPaginator(per int, nums int64) *web.Paginator

Jump to

Keyboard shortcuts

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