0
0
mirror of https://github.com/rls-moe/nyx synced 2024-09-28 16:03:47 +02:00
nyx/http/middle/session.go

43 lines
733 B
Go
Raw Normal View History

package middle
import (
"github.com/icza/session"
2017-03-16 20:08:15 +01:00
"go.rls.moe/nyx/config"
"net/http"
)
2017-03-16 20:08:15 +01:00
func SetupSessionManager(c *config.Config) {
session.Global.Close()
2017-03-16 20:08:15 +01:00
session.Global = session.NewCookieManagerOptions(session.NewInMemStore(),
&session.CookieMngrOptions{
AllowHTTP: c.DisableSecurity,
})
}
func GetSession(r *http.Request) session.Session {
return session.Get(r)
}
func IsAdminSession(sess session.Session) bool {
if sess == nil {
return false
}
if sess.CAttr("mode") == "admin" {
return true
}
return false
}
func IsModSession(sess session.Session) bool {
if sess == nil {
return false
}
if IsAdminSession(sess) {
return true
}
if sess.CAttr("mode") == "mod" {
return true
}
return false
}