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


Golang Context.GetCookie方法代码示例

本文整理汇总了Golang中github.com/Cepave/grafana/pkg/middleware.Context.GetCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetCookie方法的具体用法?Golang Context.GetCookie怎么用?Golang Context.GetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Cepave/grafana/pkg/middleware.Context的用法示例。


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

示例1: tryLoginUsingRememberCookie

func tryLoginUsingRememberCookie(c *middleware.Context) bool {
	// Check auto-login.
	uname := c.GetCookie(setting.CookieUserName)
	if len(uname) == 0 {
		return false
	}

	isSucceed := false
	defer func() {
		if !isSucceed {
			log.Trace("auto-login cookie cleared: %s", uname)
			c.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl+"/")
			c.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl+"/")
			return
		}
	}()

	userQuery := m.GetUserByLoginQuery{LoginOrEmail: uname}
	if err := bus.Dispatch(&userQuery); err != nil {
		return false
	}

	user := userQuery.Result

	// validate remember me cookie
	if val, _ := c.GetSuperSecureCookie(
		util.EncodeMd5(user.Rands+user.Password), setting.CookieRememberName); val != user.Login {
		return false
	}

	isSucceed = true
	loginUserWithUser(user, c)
	return true
}
开发者ID:Cepave,项目名称:grafana,代码行数:34,代码来源:login.go

示例2: LoginPost

func LoginPost(c *middleware.Context, cmd dtos.LoginCommand) Response {
	authQuery := login.LoginUserQuery{
		Username: cmd.User,
		Password: cmd.Password,
	}

	if err := bus.Dispatch(&authQuery); err != nil {
		if err == login.ErrInvalidCredentials {
			return ApiError(401, "Invalid username or password", err)
		}

		return ApiError(500, "Error while trying to authenticate user", err)
	}

	user := authQuery.User

	loginUserWithUser(user, c)

	result := map[string]interface{}{
		"message": "Logged in",
	}

	if redirectTo, _ := url.QueryUnescape(c.GetCookie("redirect_to")); len(redirectTo) > 0 {
		result["redirectUrl"] = redirectTo
		c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
	}

	metrics.M_Api_Login_Post.Inc(1)

	return Json(200, result)
}
开发者ID:Cepave,项目名称:grafana,代码行数:31,代码来源:login.go

示例3: LoginView

func LoginView(c *middleware.Context) {
	sig := c.GetCookie("sig")
	if len(sig) > 0 {
		c.Redirect(setting.AppSubUrl + "/")
		return
	} else {
		c.Redirect(setting.ConfigOpenFalcon.Login)
		return
	}

	if err := setIndexViewData(c); err != nil {
		c.Handle(500, "Failed to get settings", err)
		return
	}

	settings := c.Data["Settings"].(map[string]interface{})
	settings["googleAuthEnabled"] = setting.OAuthService.Google
	settings["githubAuthEnabled"] = setting.OAuthService.GitHub
	settings["disableUserSignUp"] = !setting.AllowUserSignUp

	if !tryLoginUsingRememberCookie(c) {
		c.HTML(200, VIEW_INDEX)
		return
	}

	if redirectTo, _ := url.QueryUnescape(c.GetCookie("redirect_to")); len(redirectTo) > 0 {
		c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
		c.Redirect(redirectTo)
		return
	}

	c.Redirect(setting.AppSubUrl + "/")
}
开发者ID:Cepave,项目名称:grafana,代码行数:33,代码来源:login.go

示例4: GetLoginUrl

/**
 * @function name:   func GetHomepageUrl(w http.ResponseWriter, c *middleware.Context)
 * @description:     This function returns URL of login page.
 * @related issues:  OWL-201
 * @param:           w http.ResponseWriter
 * @param:           c *middleware.Context
 * @return:          void
 * @author:          Don Hsieh
 * @since:           12/10/2015
 * @last modified:   12/10/2015
 * @called by:       func Register(r *macaron.Macaron)
 *                    in grafana/pkg/api/api.go
 */
func GetLoginUrl(w http.ResponseWriter, c *middleware.Context) {
	url := ""
	sig := c.GetCookie("sig")
	if len(sig) == 0 {
		url = setting.ConfigOpenFalcon.Login
	}
	RenderJson(w, url)
}
开发者ID:donh,项目名称:grafana,代码行数:21,代码来源:api.go


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