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 (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()
}
Ejemplo n.º 3
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 (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
	}
}