Beispiel #1
0
func safeErrorMessage(app *forest.App, ctx *bear.Context,
	friendly string) string {
	if err, ok := ctx.Get(forest.SafeError).(error); ok && err != nil {
		return err.Error()
	} else if err, ok := ctx.Get(forest.Error).(error); ok && err != nil {
		return safeErrorFilter(app, err, friendly).Error()
	} else {
		return friendly
	}
}
func (app *router) sessionDelIntercept(ctx *bear.Context) {
	sessionID := ctx.Get(forest.SessionID).(string)
	if sessionID == sessionIDWithSelfDestruct {
		ctx.Set(forest.SessionID, nil)
	}
	if sessionID == sessionIDWithUserDestruct {
		ctx.Set(forest.SessionUserID, nil)
	}
	ctx.Next()
}
func (app *router) sessionVerify(ctx *bear.Context) {
	_, ok := ctx.Get(forest.SessionID).(string)
	if !ok {
		ctx.Set(forest.Error, errors.New("sessionVerify failed"))
		app.Ware("ServerError")(ctx)
		return
	} else {
		ctx.Next()
	}
}
func (manager *sessionManager) Marshal(ctx *bear.Context) ([]byte, error) {
	sessionID := ctx.Get(forest.SessionID).(string)
	if sessionID == sessionIDWithMarshalError {
		return nil, errors.New("manager.Marshal error")
	}
	if sessionID == sessionIDWithSelfDestruct {
		ctx.Set(forest.SessionID, nil)
	}
	if sessionID == sessionIDWithUserDestruct {
		ctx.Set(forest.SessionUserID, nil)
	}
	return []byte(sessionUserJSON), nil
}
func (manager *sessionManager) Create(sessionID string, userID string,
	userJSON string, ctx *bear.Context) error {
	testError, ok := ctx.Get("testerror").(bool)
	if !ok {
		testError = false
	}
	if testError {
		return errors.New("manager.Create error")
	} else {
		ctx.Set(forest.SessionID, sessionID)
		ctx.Set(forest.SessionUserID, userID)
		return nil
	}
}
func (app *router) sessionCreateError(ctx *bear.Context) {
	ctx.Set("testerror", true).Next()
}
func (app *router) initPostParse(ctx *bear.Context) {
	ctx.Set(forest.Body, new(postBody)).Next()
}
func (app *router) customSafeErrorFilterSuccess(ctx *bear.Context) {
	ctx.Set(forest.Error, errors.New(customSafeErrorMessage))
	app.Ware("ServerError")(ctx)
}
func (app *router) authenticate(ctx *bear.Context) {
	ctx.Set(forest.SessionID, sessionIDExistent)
	ctx.Set(forest.SessionUserID, sessionUserID)
	ctx.Next()
}
func (manager *sessionManager) CreateEmpty(sessionID string,
	ctx *bear.Context) {
	ctx.Set(forest.SessionID, sessionID)
}