2017-03-12 19:37:53 +00:00
|
|
|
package middle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/icza/session"
|
2017-03-16 19:08:15 +00:00
|
|
|
"go.rls.moe/nyx/config"
|
2017-03-12 19:37:53 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2017-03-16 19:08:15 +00:00
|
|
|
func SetupSessionManager(c *config.Config) {
|
2017-03-12 19:37:53 +00:00
|
|
|
session.Global.Close()
|
2017-03-16 19:08:15 +00:00
|
|
|
session.Global = session.NewCookieManagerOptions(session.NewInMemStore(),
|
|
|
|
&session.CookieMngrOptions{
|
|
|
|
AllowHTTP: c.DisableSecurity,
|
|
|
|
})
|
2017-03-12 19:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetSession(r *http.Request) session.Session {
|
|
|
|
return session.Get(r)
|
|
|
|
}
|
2017-03-15 08:13:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|