mirror of https://gitee.com/godoos/godoos.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
846 B
33 lines
846 B
package middleware
|
|
|
|
import (
|
|
"godocms/common"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-contrib/sessions"
|
|
"github.com/gin-contrib/sessions/cookie"
|
|
gormsessions "github.com/gin-contrib/sessions/gorm"
|
|
"github.com/gin-contrib/sessions/memstore"
|
|
)
|
|
|
|
func GetSessionStore() gormsessions.Store {
|
|
|
|
if common.Config.System.SessionType == "cookie" {
|
|
// 创建一个 cookie store
|
|
store := cookie.NewStore([]byte(common.Config.System.SessionSecret))
|
|
|
|
// 配置 cookie,使用 github.com/gin-contrib/sessions.Options 类型
|
|
store.Options(sessions.Options{
|
|
Path: "/",
|
|
HttpOnly: true,
|
|
Secure: false, // 如果使用 HTTPS
|
|
SameSite: http.SameSiteNoneMode,
|
|
MaxAge: int(24 * time.Hour / time.Second), // MaxAge 单位为秒
|
|
})
|
|
|
|
return store
|
|
} else {
|
|
return memstore.NewStore([]byte(common.Config.System.SessionSecret))
|
|
}
|
|
}
|
|
|