本文整理汇总了Golang中github.com/smallnewer/gogs/modules/middleware.Context.GetCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetCookie方法的具体用法?Golang Context.GetCookie怎么用?Golang Context.GetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/smallnewer/gogs/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.GetCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SignInPost
func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
ctx.Data["Title"] = ctx.Tr("sign_in")
if ctx.HasError() {
ctx.HTML(200, SIGNIN)
return
}
u, err := models.UserSignIn(form.UserName, form.Password)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), SIGNIN, &form)
} else {
ctx.Handle(500, "UserSignIn", err)
}
return
}
if form.Remember {
days := 86400 * setting.LogInRememberDays
ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubUrl)
ctx.SetSuperSecureCookie(base.EncodeMd5(u.Rands+u.Passwd),
setting.CookieRememberName, u.Name, days, setting.AppSubUrl)
}
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
ctx.Redirect(redirectTo)
return
}
ctx.Redirect(setting.AppSubUrl + "/")
}
示例2: Home
func Home(ctx *middleware.Context) {
if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
ctx.HTML(200, user.ACTIVATE)
} else {
user.Dashboard(ctx)
}
return
}
// Check auto-login.
uname := ctx.GetCookie(setting.CookieUserName)
if len(uname) != 0 {
ctx.Redirect(setting.AppSubUrl + "/user/login")
return
}
ctx.Data["PageIsHome"] = true
ctx.HTML(200, HOME)
}
示例3: SignIn
func SignIn(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
// Check auto-login.
isSucceed, err := middleware.AutoSignIn(ctx)
if err != nil {
ctx.Handle(500, "AutoSignIn", err)
return
}
if isSucceed {
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
ctx.Redirect(redirectTo)
}
ctx.Redirect(setting.AppSubUrl + "/")
return
}
ctx.HTML(200, SIGNIN)
}