Modify: using memstore to store session
This commit is contained in:
parent
1db0c6116e
commit
2ae2c9b784
3 changed files with 8 additions and 8 deletions
|
@ -2,13 +2,13 @@ package middleware
|
|||
|
||||
import (
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-contrib/sessions/memstore"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Session 初始化session
|
||||
func Session(secret string) gin.HandlerFunc {
|
||||
store := cookie.NewStore([]byte(secret))
|
||||
store := memstore.NewStore([]byte(secret))
|
||||
//Also set Secure: true if using SSL, you should though
|
||||
store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"})
|
||||
return sessions.Sessions("cloudreve-session", store)
|
||||
|
|
|
@ -26,18 +26,18 @@ type User struct {
|
|||
gorm.Model
|
||||
Email string `gorm:"type:varchar(100);unique_index"`
|
||||
Nick string `gorm:"size:50"`
|
||||
Password string
|
||||
Password string `json:"-"`
|
||||
Status int
|
||||
Group int
|
||||
PrimaryGroup int
|
||||
ActivationKey string
|
||||
ActivationKey string `json:"-"`
|
||||
Storage int64
|
||||
LastNotify *time.Time
|
||||
OpenID string
|
||||
TwoFactor string
|
||||
OpenID string `json:"-"`
|
||||
TwoFactor string `json:"-"`
|
||||
Delay int
|
||||
Avatar string
|
||||
Options string `gorm:"size:4096"`
|
||||
Options string `json:"-",gorm:"size:4096"`
|
||||
OptionsSerialized serializer.UserOption `gorm:"-"`
|
||||
}
|
||||
|
||||
|
|
|
@ -42,13 +42,13 @@ func (service *UserLoginService) Login(c *gin.Context) serializer.Response {
|
|||
}
|
||||
|
||||
//登陆成功,清空并设置session
|
||||
ClearSession(c)
|
||||
SetSession(c, map[string]interface{}{
|
||||
"user_id": expectedUser.ID,
|
||||
})
|
||||
|
||||
return serializer.Response{
|
||||
Code: 0,
|
||||
Data: &expectedUser,
|
||||
Msg: "",
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue