本文整理汇总了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 "退出成功"
}