// 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 }
// 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 "" }
// 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 }
// 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 }