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


Golang Session.Delete方法代碼示例

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


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

示例1: UserLogin

func UserLogin(r *http.Request, db *sql.DB, s sessions.Session, rw http.ResponseWriter) (int, string) {
	var id string
	var pass string

	email, password := r.FormValue("email"), r.FormValue("password")
	err := db.QueryRow("select id, password from appuser where email=$1", email).Scan(&id, &pass)

	if err != nil || bcrypt.CompareHashAndPassword([]byte(pass), []byte(password)) != nil {
		//return 401, "Not Authorized. Buuuurn!"
		http.Redirect(rw, r, "/wrong", http.StatusFound)
	}

	//set the user id in the session
	s.Set("userId", id)

	//return user
	if returnUrl, ok := s.Get("returnUrl").(string); ok {
		s.Delete("returnUrl")
		http.Redirect(rw, r, returnUrl, http.StatusFound)
	} else {
		http.Redirect(rw, r, "/", http.StatusFound)
	}

	return 200, "User id is " + id
}
開發者ID:qapi,項目名稱:goblog-playground,代碼行數:25,代碼來源:main.go

示例2: getSignin

func getSignin(s sessions.Session, w http.ResponseWriter, r *http.Request) {
	s.Delete("username")
	if !oauthEnabled() {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	body, err := Asset("templates/signin.html")
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("ERROR: %s", err)
		return
	}

	tmpl, err := template.New("config.js").Parse(string(body))
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("ERROR: %s", err)
		return
	}

	err = tmpl.Execute(w, struct {
		Error  string
		Google bool
	}{
		Error:  r.FormValue("error"),
		Google: googleOauthEnabled(),
	})
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("ERROR: %s", err)
		return
	}
}
開發者ID:carriercomm,項目名稱:gofana,代碼行數:34,代碼來源:main.go

示例3: inner_GET_authorize

func inner_GET_authorize(c martini.Context, sess sessions.Session, r *http.Request, ar *osin.AuthorizeRequest) bool {
	var (
		identity = ActiveIdentity(c)
		source   = current_url(r)
		handler  martini.Handler
	)

	if identity != nil {
		ar.UserData = identity
		sess.Delete("flow")
		return true
	} else {
		sess.Set("flow", FlowState{
			Type:    AuthorizeFlow,
			Source:  source,
			StartAt: time.Now(),
		})

		if provider := r.URL.Query().Get("p"); provider == "" {
			handler = show_provider_chooser()
		} else {
			handler = redirect_to_provider(provider)
		}
	}

	c.Invoke(handler)
	return false
}
開發者ID:rogeriomarques,項目名稱:oapx,代碼行數:28,代碼來源:flow.go

示例4: HandleLogout

func (s *AEServer) HandleLogout(session sessions.Session) {
	toki := session.Get("Login")
	if toki == nil {
		return
	}
	s.ch_logout <- toki.(string)
	session.Delete("Login")
}
開發者ID:boreys,項目名稱:askeecs,代碼行數:8,代碼來源:routing.go

示例5: getFlash

func getFlash(session sessions.Session, key string) string {
	value := session.Get(key)

	if value == nil {
		return ""
	} else {
		session.Delete(key)
		return value.(string)
	}
}
開發者ID:shogo82148,項目名稱:isucon4_powawa,代碼行數:10,代碼來源:util.go

示例6: LogoutUser

// LogoutUser is a route which deletes session cookie "user", from the given client.
// On API call responds with HTTP 200 body and on frontend the client is redirected to homepage "/".
func LogoutUser(req *http.Request, s sessions.Session, res render.Render) {
	s.Delete("user")
	switch Root(req) {
	case "api":
		res.JSON(200, map[string]interface{}{"success": "You've been logged out."})
		return
	case "user":
		res.Redirect("/", 302)
		return
	}
}
開發者ID:freeformz,項目名稱:vertigo,代碼行數:13,代碼來源:users.go

示例7: must_authenticate

func must_authenticate(c martini.Context, sess sessions.Session, db *sqlx.DB, r *http.Request) {
	identity := ActiveIdentity(c)

	if identity != nil {
		return
	}

	if r.Header.Get("x-interactive") == "true" {
		sess.Delete("identity_id")
		c.Invoke(redirect_to("/login"))
	} else {
		c.Invoke(forbidden())
	}
}
開發者ID:rogeriomarques,項目名稱:oapx,代碼行數:14,代碼來源:do_authenticate.go

示例8: oauth2callback

func oauth2callback(params martini.Params, s sessions.Session, c martini.Context, w http.ResponseWriter, r *http.Request) {
	providerName := params["provider"]
	if providerName == "" {
		http.Error(w, "Unknown provider", http.StatusBadRequest)
		return
	}

	provider, err := gomniauth.Provider(providerName)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("ERROR: %s", err)
		return
	}

	omap, err := objx.FromURLQuery(r.URL.RawQuery)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	creds, err := provider.CompleteAuth(omap)
	if err != nil {
		s.Delete("username")
		http.Redirect(w, r, "/signin?error=Access+Denied", http.StatusFound)
		log.Printf("ERROR: %s", err)
		return
	}

	user, err := provider.GetUser(creds)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("ERROR: %s", err)
		return
	}

	if strings.HasSuffix(user.Email(), authDomain) {
		log.Printf("%s authenticated via %s", user.Email(), providerName)
		s.Set("username", user.Email())
	} else {
		http.Redirect(w, r, "/signin", http.StatusFound)
		return
	}

	http.Redirect(w, r, "/", http.StatusFound)
}
開發者ID:carriercomm,項目名稱:gofana,代碼行數:45,代碼來源:main.go

示例9: GET_login

func GET_login(c martini.Context, sess sessions.Session, r *http.Request) {
	var (
		identity = ActiveIdentity(c)
		source   = r.Referer()
		handler  martini.Handler
	)

	if identity != nil {
		sess.Delete("flow")
		handler = redirect_to(source)
	} else {
		sess.Set("flow", FlowState{
			Type:    LoginFlow,
			Source:  source,
			StartAt: time.Now(),
		})
		handler = show_provider_chooser()
	}

	c.Invoke(handler)
}
開發者ID:rogeriomarques,項目名稱:oapx,代碼行數:21,代碼來源:flow.go

示例10: GET_link

func GET_link(c martini.Context, sess sessions.Session, r *http.Request) {
	var (
		identity = ActiveIdentity(c)
		source   = r.Referer()
		handler  martini.Handler
	)

	if identity == nil {
		sess.Delete("flow")
		handler = forbidden()
	} else {
		sess.Set("flow", FlowState{
			Type:       LinkFlow,
			Source:     source,
			IdentityId: identity.Id,
			StartAt:    time.Now(),
		})
		handler = show_provider_chooser()
	}

	c.Invoke(handler)
}
開發者ID:rogeriomarques,項目名稱:oapx,代碼行數:22,代碼來源:flow.go

示例11: editReruenInfo

func editReruenInfo(params martini.Params, session sessions.Session, r render.Render) {
	user_number := session.Get("user_number")
	user_name := session.Get("user_name")
	if user_number == nil || user_name == nil {
		r.HTML(200, "home", nil)
	}
	if params["status"] == "success" {
		msg := EditReturnInfo{
			Status:  true,
			Message: "修改成功!",
		}
		session.Delete("user_name")
		session.Delete("user_number")
		r.HTML(200, "editReruenInfo", msg)
	} else {
		msg := EditReturnInfo{
			Status:  false,
			Message: "對不起!修改失敗!",
		}
		r.HTML(200, "editReruenInfo", msg)
	}
}
開發者ID:cwen-coder,項目名稱:youth,代碼行數:22,代碼來源:youth.go

示例12: Logout

func Logout(ren render.Render, req *http.Request, s sessions.Session) {
	s.Delete("userId")
	ren.JSON(http.StatusAccepted, nil)
}
開發者ID:ukitazume,項目名稱:bunkai,代碼行數:4,代碼來源:server.go

示例13: Logout

func Logout(session sessions.Session, r render.Render) {
	v := session.Get("userid")
	fmt.Println(v)
	session.Delete("userid")
	r.HTML(200, "login", "登出成功")
}
開發者ID:payallmoney,項目名稱:sharego,代碼行數:6,代碼來源:auth.go

示例14: LogoutHandler

func LogoutHandler(w http.ResponseWriter, req *http.Request, session sessions.Session) {
	session.Delete("username")
	http.Redirect(w, req, "/login", http.StatusFound)
}
開發者ID:chinab,項目名稱:enterprise-manage,代碼行數:4,代碼來源:login.go

示例15: Logout

func Logout(rw http.ResponseWriter, req *http.Request, s sessions.Session) {
	s.Delete("userId")
	http.Redirect(rw, req, "/", http.StatusFound)
}
開發者ID:RajeshReddyM,項目名稱:Lessons,代碼行數:4,代碼來源:main.go


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