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


Golang Session.Clear方法代碼示例

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


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

示例1: RequireLogin

// Handler to require a user to log in. If the user is currently logged in
// nothing happens. Otherwise clear existing session and redirect the user
// to the login page
func RequireLogin(s sessions.Session, r render.Render) {
	session := s.Get("user_session")
	if session == nil {
		s.Clear()
		r.Redirect("/login")
	}
}
開發者ID:sausheong,項目名稱:goauthserv,代碼行數:10,代碼來源:routes.go

示例2: DoLogin

func DoLogin(entity models.UserLogin, session sessions.Session, enc Encoder, db gorp.SqlExecutor) (int, string) {

	status := &models.DefaultStruct{
		Id:       http.StatusForbidden,
		Name:     messages.GetLocaleMessage("en", "MSG_LOGIN_INVALID"),
		Lang_key: "en",
	}

	user := GetUserByLogin(entity, db)

	if user.Name != "" {

		err := sessionauth.AuthenticateSession(session, user)
		if err != nil {
			status.Name = messages.GetLocaleMessage("en", "MSG_SESSION_INIT_ERROR")
			return http.StatusForbidden, Must(enc.EncodeOne(status))
		}
		user.Authenticated = true
		user.UpdateLastLogin()
		status.Name = messages.GetLocaleMessage("en", "MSG_SUCCESSFUL_LOGIN")
		return http.StatusOK, Must(enc.EncodeOne(user))

	} else {

		sessionauth.Logout(session, user)
		session.Clear()
		return http.StatusForbidden, Must(enc.EncodeOne(status))

	}

	return http.StatusForbidden, Must(enc.EncodeOne(status))
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:32,代碼來源:user.go

示例3: RequestData

/* Middleware to:
   - Retrieve data from github if user is logged in and data is not stored in sessions
   - Delete session data if user logged out */
func RequestData(tokens oauth2.Tokens, session sessions.Session) {
	if !tokens.Expired() && session.Get("username") == nil {
		access := tokens.Access()
		req, _ := http.NewRequest("GET", "https://api.github.com/user?access_token="+access, nil)
		client := &http.Client{}
		resp, _ := client.Do(req)

		body, _ := ioutil.ReadAll(resp.Body)

		parse := map[string]interface{}{}
		json.Unmarshal([]byte(string(body)), &parse)
		session.Set("username", parse["login"])
		session.Set("user_id", parse["id"])
		session.Set("avatar", parse["avatar_url"])

		log.Println("retrieved data")
	} else if tokens.Expired() && session.Get("username") != nil {
		session.Clear()
		log.Println("removed data")
	}
}
開發者ID:TimothyGu,項目名稱:website,代碼行數:24,代碼來源:middleware.go

示例4: DoLogout

func DoLogout(enc Encoder, session sessions.Session, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage("en", "MSG_LOGIN_REQUIRED"),
		Lang_key: "en",
	}

	if user.IsAuthenticated() {

		sessionauth.Logout(session, user)
		session.Clear()
		status.Name = messages.GetLocaleMessage("en", "MSG_SUCCESSFUL_LOGOUT")
	}

	updateUser := UserById(user.UniqueId().(int), db)

	updateUser.Authenticated = false
	db.Update(updateUser)

	return http.StatusOK, Must(enc.EncodeOne(status))
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:22,代碼來源:user.go

示例5: welcome

func (web *MailWeb) welcome(session sessions.Session, r render.Render) {
	session.Clear()
	r.HTML(200, "start", nil)
}
開發者ID:mdrobek,項目名稱:watney,代碼行數:4,代碼來源:web.go

示例6: LogoutAction

func LogoutAction(session sessions.Session, re render.Render) {
	session.Clear()
	re.Redirect("/")
}
開發者ID:SemQuery,項目名稱:web,代碼行數:4,代碼來源:session.go

示例7: GetLogout

// GET /logout
func GetLogout(s sessions.Session, r render.Render) {
	s.Clear()
	r.Redirect("/login")
}
開發者ID:sausheong,項目名稱:goauthserv,代碼行數:5,代碼來源:routes.go

示例8: LogOut

func LogOut(session sessions.Session) string {
	session.Clear()
	return "退出成功"
}
開發者ID:go-galaxy,項目名稱:galaxy,代碼行數:4,代碼來源:example.go


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