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