當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SecureCookie.Decode方法代碼示例

本文整理匯總了Golang中github.com/gorilla/securecookie.SecureCookie.Decode方法的典型用法代碼示例。如果您正苦於以下問題:Golang SecureCookie.Decode方法的具體用法?Golang SecureCookie.Decode怎麽用?Golang SecureCookie.Decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gorilla/securecookie.SecureCookie的用法示例。


在下文中一共展示了SecureCookie.Decode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: LoggedIn

func LoggedIn(w http.ResponseWriter, r *http.Request, s *securecookie.SecureCookie) bool {
	if cookie, err := r.Cookie("whiteboard"); err == nil {
		value := make(map[string]string)
		if err = s.Decode("whiteboard", cookie.Value, &value); err == nil {
			return true
		}
		return false
	}
	return false
}
開發者ID:hunterpraska,項目名稱:Whiteboard,代碼行數:10,代碼來源:auth.go

示例2: FetchCookie

func FetchCookie(r *http.Request, storedCookie *securecookie.SecureCookie, cookieName string) string {
	if cookie, err := r.Cookie(cookieName); err == nil {
		value := make(map[string]string)
		if cookie != nil {
			err = storedCookie.Decode(cookieName, cookie.Value, &value)
			if len(value[cookieName]) > 0 && err == nil {
				return value[cookieName]
			}
		}
	}

	return ""
}
開發者ID:rjourde,項目名稱:udacity.cs253.go,代碼行數:13,代碼來源:cookies.go

示例3: VerifyXSRFToken

func VerifyXSRFToken(w http.ResponseWriter, r *http.Request, sessionStore sessions.Store, secureCookie *securecookie.SecureCookie) bool {
	xsrftoken := r.Header.Get(XSRFTOKENHEADER)
	userID := ""

	err := secureCookie.Decode(XSRFTOKEN, xsrftoken, &userID)
	if err == nil {
		session, _ := sessionStore.Get(r, SESSIONNAME)

		if userID != "" && userID == session.Values["username"].(string) {
			xlog.Infof("XSRF verification success for user %s", session.Values["username"].(string))
			return true
		}
		xlog.Errorf("XSRF issue: userID = %s session = %s", userID, session.Values["username"].(string))
	}

	xlog.Errorf("XSRF verification failed: %v (Request: %#v", err, *r)
	http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
	StatCount("XSRF verification failed", 1)
	return false
}
開發者ID:joinmytalk,項目名稱:satsuma,代碼行數:20,代碼來源:login.go


注:本文中的github.com/gorilla/securecookie.SecureCookie.Decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。