本文整理匯總了Golang中github.com/gogits/session.SessionStore類的典型用法代碼示例。如果您正苦於以下問題:Golang SessionStore類的具體用法?Golang SessionStore怎麽用?Golang SessionStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SessionStore類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(header http.Header, sess session.SessionStore) int64 {
if !models.HasEngine {
return 0
}
if setting.Service.EnableReverseProxyAuth {
webAuthUser := header.Get(setting.ReverseProxyAuthUser)
if len(webAuthUser) > 0 {
u, err := models.GetUserByName(webAuthUser)
if err != nil {
if err != models.ErrUserNotExist {
log.Error("auth.user.SignedInId(GetUserByName): %v", err)
}
return 0
}
return u.Id
}
}
uid := sess.Get("userId")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserById(id); err != nil {
if err != models.ErrUserNotExist {
log.Error("auth.user.SignedInId(GetUserById): %v", err)
}
return 0
}
return id
}
return 0
}
示例2: SignedInName
// SignedInName returns the name of signed in user.
func SignedInName(sess session.SessionStore) string {
uname := sess.Get("userName")
if uname == nil {
return ""
}
if s, ok := uname.(string); ok {
return s
}
return ""
}
示例3: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(sess session.SessionStore) int64 {
if !models.HasEngine {
return 0
}
uid := sess.Get("userId")
if uid == nil {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserById(id); err != nil {
return 0
}
return id
}
return 0
}
示例4: SignedInId
// SignedInId returns the id of signed in user.
func SignedInId(session session.SessionStore) int64 {
userId := session.Get("userId")
if userId == nil {
return 0
}
if s, ok := userId.(int64); ok {
if _, err := models.GetUserById(s); err != nil {
return 0
}
return s
}
return 0
}