当前位置: 首页>>代码示例>>Golang>>正文


Golang context.Context类代码示例

本文整理汇总了Golang中github.com/astaxie/beego/context.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ViewLogin

func ViewLogin(c *context.Context) {
	cookie := c.GetCookie("MtimeCIUserId")
	if len(cookie) <= 0 {
		c.Redirect(302, "/login?url="+url.QueryEscape(c.Input.Uri()))
	}
	beego.Informational(cookie)
}
开发者ID:beerbubble,项目名称:MtimeCI,代码行数:7,代码来源:Login.go

示例2: HandleAccess

func HandleAccess(ctx *context.Context) {
	token := ctx.GetCookie("epic_user_token")
	ok, _ := tools.VerifyToken(token)
	if len(token) != 0 && ok {
		ctx.Redirect(302, "/succeed")
	}
}
开发者ID:EPICPaaS,项目名称:account,代码行数:7,代码来源:filter.go

示例3: LoginUserFromRememberCookie

func LoginUserFromRememberCookie(user *models.User, ctx *context.Context) (success bool) {
	userName := ctx.GetCookie(setting.CookieUserName)
	if len(userName) == 0 {
		return false
	}

	defer func() {
		if !success {
			DeleteRememberCookie(ctx)
		}
	}()

	user.UserName = userName
	if err := user.Read("UserName"); err != nil {
		return false
	}

	secret := utils.EncodeMd5(user.Rands + user.Password)
	value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
	if value != userName {
		return false
	}

	LoginUser(user, ctx, true)

	return true
}
开发者ID:wildex,项目名称:wetalk,代码行数:27,代码来源:auth.go

示例4: FilterUser

func FilterUser(ctx *context.Context) {
	if (ctx.Input.IsGet() || ctx.Input.IsPost()) && (ctx.Input.URL() == loginPageURL || ctx.Input.URL() == logoutPageURL) {
		// Don't redirect itself to prevent the circle
	} else {
		user, ok := ctx.Input.Session("user").(*rbac.User)

		if ok == false {
			if guiMessage := guimessagedisplay.GetGUIMessageFromContext(ctx); guiMessage != nil {
				guiMessage.AddDanger("Unauthorized")
			}
			ctx.Redirect(302, loginPageURL)
		} else {
			// Authorize
			if user.HasPermission(componentName, ctx.Input.Method(), ctx.Input.URL()) == false {
				if guiMessage := guimessagedisplay.GetGUIMessageFromContext(ctx); guiMessage != nil {
					guiMessage.AddDanger("User is not authorized to this page. Please use another user with priviledge.")
				}
				ctx.Redirect(302, loginPageURL)
			}

			// Resource check is in another place since GUI doesn't place the resource name in url

			// Audit log
			go func() {
				sendAuditLog(ctx, user.Name, true)
			}()
		}
	}
}
开发者ID:cloudawan,项目名称:cloudone_gui,代码行数:29,代码来源:identity.go

示例5: LoginUserFromRememberCookie

func (this *BaseController) LoginUserFromRememberCookie(u *user.User, ctx *context.Context) (success bool) {
	userName := ctx.GetCookie(setting.CookieUsername)
	if len(userName) == 0 {
		return false
	}

	defer func() {
		if !success {
			this.DeleteRememberCookie(ctx)
		}
	}()
	u.Username = userName
	if err := this.UserService.Read(u, "Username"); err != nil {
		return false
	}

	secret := utils.EncodeMd5(u.PasswordSalt + u.Password)
	value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
	if value != userName {
		return false
	}

	this.LoginUserRememberCookie(u, ctx, true)

	return true
}
开发者ID:thanzen,项目名称:identity,代码行数:26,代码来源:base.go

示例6: Handler

// Handler beego filter handler for serve captcha image
func (c *Captcha) Handler(ctx *context.Context) {
	var chars []byte

	id := path.Base(ctx.Request.RequestURI)
	if i := strings.Index(id, "."); i != -1 {
		id = id[:i]
	}

	key := c.key(id)

	if len(ctx.Input.Query("reload")) > 0 {
		chars = c.genRandChars()
		if err := c.store.Put(key, chars, c.Expiration); err != nil {
			ctx.Output.SetStatus(500)
			ctx.WriteString("captcha reload error")
			beego.Error("Reload Create Captcha Error:", err)
			return
		}
	} else {
		if v, ok := c.store.Get(key).([]byte); ok {
			chars = v
		} else {
			ctx.Output.SetStatus(404)
			ctx.WriteString("captcha not found")
			return
		}
	}

	img := NewImage(chars, c.StdWidth, c.StdHeight)
	if _, err := img.WriteTo(ctx.ResponseWriter); err != nil {
		beego.Error("Write Captcha Image Error:", err)
	}
}
开发者ID:kingljl,项目名称:beego,代码行数:34,代码来源:captcha.go

示例7: Render

// Render takes a Beego context, template name and a Context (map[string]interface{}).
// The template is parsed and cached, and gets executed into beegoCtx's ResponseWriter.
//
// Templates are looked up in `templates/` instead of Beego's default `views/` so that
// Beego doesn't attempt to load and parse our templates with `html/template`.
func Render(beegoCtx *context.Context, tmpl string, ctx Context) error {
	template, err := p2.FromCache(path.Join(templateDir, tmpl))
	if err != nil {
		panic(err)
	}

	var pCtx p2.Context
	if ctx == nil {
		pCtx = p2.Context{}
	} else {
		pCtx = p2.Context(ctx)
	}

	if xsrf, ok := beegoCtx.GetSecureCookie(beego.BConfig.WebConfig.XSRFKey, "_xsrf"); ok {
		pCtx["_xsrf"] = xsrf
	}

	// Only override "flash" if it hasn't already been set in Context
	if _, ok := ctx["flash"]; !ok {
		if ctx == nil {
			ctx = Context{}
		}
		ctx["flash"] = readFlash(beegoCtx)
	}

	return template.ExecuteWriter(pCtx, beegoCtx.ResponseWriter)
}
开发者ID:yansuan,项目名称:beego-pongo2,代码行数:32,代码来源:main.go

示例8: checkLogin

// 检测登录,跳转登录界面
func checkLogin(c *context.Context) {
	uid, ok := c.Input.Session("uid").(int64)
	if !ok || uid <= 0 {
		if c.Request.RequestURI != "/login" {
			c.Redirect(302, "/login")
		}
	}
}
开发者ID:xxoommd,项目名称:SimpleAccountSystem,代码行数:9,代码来源:custom_controller.go

示例9: recoverPanic

func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
	if err := recover(); err != nil {
		if err == USERSTOPRUN {
			return
		}
		if RunMode == "dev" {
			if !RecoverPanic {
				panic(err)
			} else {
				if ErrorsShow {
					if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok {
						executeError(handler, context)
						return
					}
				}
				var stack string
				Critical("the request url is ", context.Input.Url())
				Critical("Handler crashed with error", err)
				for i := 1; ; i++ {
					_, file, line, ok := runtime.Caller(i)
					if !ok {
						break
					}
					Critical(fmt.Sprintf("%s:%d", file, line))
					stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line))
				}
				showErr(err, context, stack)
			}
		} else {
			if !RecoverPanic {
				panic(err)
			} else {
				// in production model show all infomation
				if ErrorsShow {
					if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok {
						executeError(handler, context)
						return
					} else if handler, ok := ErrorMaps["503"]; ok {
						executeError(handler, context)
						return
					} else {
						context.WriteString(fmt.Sprint(err))
					}
				} else {
					Critical("the request url is ", context.Input.Url())
					Critical("Handler crashed with error", err)
					for i := 1; ; i++ {
						_, file, line, ok := runtime.Caller(i)
						if !ok {
							break
						}
						Critical(fmt.Sprintf("%s:%d", file, line))
					}
				}
			}
		}
	}
}
开发者ID:jamesbjackson,项目名称:seagull,代码行数:58,代码来源:router.go

示例10: FilterAuth

// FilterAuth prevents the user from accessing protected pages if they are not
// logged in.
func FilterAuth(ctx *context.Context) {
	if ctx.Input.GetData("user") == nil {
		ctx.Redirect(302, fmt.Sprintf(
			"%s?redirect=%s",
			beego.URLFor("UserController.Login"),
			url.QueryEscape(ctx.Request.URL.Path),
		))
	}
}
开发者ID:nathan-osman,项目名称:pratl,代码行数:11,代码来源:router.go

示例11: GetLoginRedirect

// get login redirect url from cookie
func GetLoginRedirect(ctx *context.Context) string {
	loginRedirect := strings.TrimSpace(ctx.GetCookie("login_to"))
	if utils.IsMatchHost(loginRedirect) == false {
		loginRedirect = "/"
	} else {
		ctx.SetCookie("login_to", "", -1, "/")
	}
	return loginRedirect
}
开发者ID:wildex,项目名称:wetalk,代码行数:10,代码来源:auth.go

示例12: IsLogin

func IsLogin(ctx *context.Context) bool {
	username := ctx.GetCookie("username")
	password := ctx.GetCookie("password")
	if beego.AppConfig.String("username") == username &&
		beego.AppConfig.String("password") == password {
		return true
	}
	return false
}
开发者ID:hippora,项目名称:hippoblog,代码行数:9,代码来源:common.go

示例13: WriteJson

func WriteJson(ctx *context.Context, i interface{}) error {
	data, err := json.Marshal(i)
	if err != nil {
		fmt.Println(err)
		return err
	}
	ctx.WriteString(string(data))
	return nil
}
开发者ID:lilwulin,项目名称:duang,代码行数:9,代码来源:utils.go

示例14: Write

func (me *StatusCode) Write(ctx *context.Context, code EUmsError, err error) {
	me.Code = int(code)

	j, _ := json.Marshal(me)

	ctx.WriteString(string(j))

	beego.Info(string(j), code.ToString(), err)
}
开发者ID:tcdog001,项目名称:ums,代码行数:9,代码来源:code.go

示例15: loginFilter

func loginFilter(ctx *context.Context) {

	user := ctx.Input.CruSession.Get("user")
	//user := this.GetSession("user")
	fmt.Println("loginFilter user")
	fmt.Println(user)
	if user == nil && ctx.Request.RequestURI != "/" && ctx.Request.RequestURI != "/login" {
		ctx.Redirect(302, "/")
	}
}
开发者ID:dishytianxiang,项目名称:just-some-go-note,代码行数:10,代码来源:router.go


注:本文中的github.com/astaxie/beego/context.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。