本文整理汇总了Golang中github.com/astaxie/beego/context.Context.GetCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetCookie方法的具体用法?Golang Context.GetCookie怎么用?Golang Context.GetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/astaxie/beego/context.Context
的用法示例。
在下文中一共展示了Context.GetCookie方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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")
}
}
示例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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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)
}
}
示例8: checkAccount
func checkAccount(ctx *context.Context) bool {
uname := ctx.GetCookie("uname")
/*if err != nil {
return false
}*/
//uname := ok.Value
passwd := ctx.GetCookie("passwd")
/*if err != nil {
return false
}*/
//passwd := ok.Value
beego.Debug("blog[debug]", uname, passwd)
if beego.AppConfig.String("uname") == uname &&
beego.AppConfig.String("passwd") == passwd {
return true
}
return false
}
示例9: DocsStatic
func DocsStatic(ctx *context.Context) {
if uri := ctx.Input.Param(":all"); len(uri) > 0 {
lang := ctx.GetCookie("lang")
if !i18n.IsExist(lang) {
lang = "en-US"
}
f, err := os.Open("docs/" + lang + "/" + "images/" + uri)
if err != nil {
ctx.WriteString(err.Error())
return
}
defer f.Close()
_, err = io.Copy(ctx.ResponseWriter, f)
if err != nil {
ctx.WriteString(err.Error())
return
}
}
}
示例10: checkAccount
func checkAccount(ctx *context.Context) bool {
uname := ctx.GetCookie("uname")
pwd := ctx.GetCookie("pwd")
return beego.AppConfig.String("uname") == uname && beego.AppConfig.String("pwd") == pwd
}