• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang context.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: handleAccess

// general use of redirect callback
func (this *SocialAuth) handleAccess(ctx *context.Context) {
	redirect, _, err := this.OAuthAccess(ctx)
	if err != nil {
		beego.Error("SocialAuth.handleAccess", err)
	}

	if len(redirect) > 0 {
		ctx.Redirect(302, redirect)
	}
}
开发者ID:naokij,项目名称:social-auth,代码行数:11,代码来源:social.go


示例17: DocsStatic

func DocsStatic(ctx *context.Context) {
	uri := ctx.Input.Params[":all"]
	if len(uri) > 0 {
		lang := ctx.GetCookie("lang")
		if !i18n.IsExist(lang) {
			lang = "en-US"
		}
		http.ServeFile(ctx.ResponseWriter, ctx.Request, "docs/"+lang+"/"+"images/"+uri)
	}
}
开发者ID:hiproz,项目名称:beeweb,代码行数:10,代码来源:docs.go


示例18: HandleRedirect

func HandleRedirect(ctx *context.Context) {
	redirect, err := SocialAuth.OAuthRedirect(ctx)
	if err != nil {
		beego.Error("SocialAuth.handleRedirect", err)
	}

	if len(redirect) > 0 {
		ctx.Redirect(302, redirect)
	}
}
开发者ID:jueebushe,项目名称:social-auth,代码行数:10,代码来源:main.go


示例19: OAuthAccess

func OAuthAccess(ctx *context.Context) {
	redirect, _, err := setting.SocialAuth.OAuthAccess(ctx)
	if err != nil {
		beego.Error("OAuthAccess", err)
	}

	if len(redirect) > 0 {
		ctx.Redirect(302, redirect)
	}
}
开发者ID:netxfly,项目名称:wetalk,代码行数:10,代码来源:auth_social.go


示例20: FilterUser

func FilterUser(ctx *context.Context) {
	adminUrl := []string{"organizations", "users", "reports"}

	for _, url := range adminUrl {
		if strings.Contains(ctx.Request.RequestURI, url) {
			if adminUser, ok := ctx.Input.Session("adminUser").(string); !ok || adminUser != beego.AppConfig.String("conf::admin_user") {
				ctx.Redirect(302, "/login")
			}
			return
		}
	}

}
开发者ID:kevinxu001,项目名称:survey,代码行数:13,代码来源:systeminit.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang httplib.Get函数代码示例发布时间:2022-05-24
下一篇:
Golang context.NewOutput函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap