mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Little change of session API + Update examples
Former-commit-id: e8c58b186acf1c8932af6e886dae7035f4d581c1
This commit is contained in:
parent
0f1a265e5a
commit
ef979cf541
|
@ -65,5 +65,10 @@ func main() {
|
|||
sess.Destroy(ctx)
|
||||
})
|
||||
|
||||
app.Get("/update", func(ctx context.Context) {
|
||||
// updates expire date with a new date
|
||||
sess.ShiftExpiraton(ctx)
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
|
|
@ -62,10 +62,16 @@ func newApp() *iris.Application {
|
|||
mySessions.Start(ctx).Clear()
|
||||
})
|
||||
|
||||
app.Get("/update", func(ctx context.Context) {
|
||||
// updates expire date with a new date
|
||||
mySessions.ShiftExpiraton(ctx)
|
||||
})
|
||||
|
||||
app.Get("/destroy", func(ctx context.Context) {
|
||||
//destroy, removes the entire session data and cookie
|
||||
mySessions.Destroy(ctx)
|
||||
}) // Note about destroy:
|
||||
})
|
||||
// Note about destroy:
|
||||
//
|
||||
// You can destroy a session outside of a handler too, using the:
|
||||
// mySessions.DestroyByID
|
||||
|
|
|
@ -69,6 +69,11 @@ func main() {
|
|||
sess.Start(ctx).Clear()
|
||||
})
|
||||
|
||||
app.Get("/update", func(ctx context.Context) {
|
||||
// updates expire date
|
||||
sess.ShiftExpiraton(ctx)
|
||||
})
|
||||
|
||||
app.Get("/destroy", func(ctx context.Context) {
|
||||
|
||||
//destroy, removes the entire session data and cookie
|
||||
|
|
|
@ -119,14 +119,19 @@ func (s *Sessions) Start(ctx context.Context) *Session {
|
|||
}
|
||||
|
||||
// ShiftExpiraton move the expire date of a session to a new date by using session default timeout configuration
|
||||
func (s *Sessions) ShiftExpiraton(ctx context.Context, sid string) {
|
||||
s.UpdateExpiraton(ctx, sid, s.config.Expires)
|
||||
func (s *Sessions) ShiftExpiraton(ctx context.Context) {
|
||||
s.UpdateExpiraton(ctx, s.config.Expires)
|
||||
}
|
||||
|
||||
// UpdateExpiraton change expire date of a session to a new date by using timeout value passed by `expires` parameter
|
||||
func (s *Sessions) UpdateExpiraton(ctx context.Context, sid string, expires time.Duration) {
|
||||
if s.provider.UpdateExpiraton(sid, expires) {
|
||||
s.updateCookie(sid, ctx, expires)
|
||||
func (s *Sessions) UpdateExpiraton(ctx context.Context, expires time.Duration) {
|
||||
cookieValue := GetCookie(ctx, s.config.Cookie)
|
||||
|
||||
if cookieValue != "" {
|
||||
sid := s.decodeCookieValue(cookieValue)
|
||||
if s.provider.UpdateExpiraton(sid, expires) {
|
||||
s.updateCookie(sid, ctx, expires)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user