本文整理匯總了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")
}
}
示例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))
}
示例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")
}
}
示例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))
}
示例5: welcome
func (web *MailWeb) welcome(session sessions.Session, r render.Render) {
session.Clear()
r.HTML(200, "start", nil)
}
示例6: LogoutAction
func LogoutAction(session sessions.Session, re render.Render) {
session.Clear()
re.Redirect("/")
}
示例7: GetLogout
// GET /logout
func GetLogout(s sessions.Session, r render.Render) {
s.Clear()
r.Redirect("/login")
}
示例8: LogOut
func LogOut(session sessions.Session) string {
session.Clear()
return "退出成功"
}