Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
fa8f6e5a
Commit
fa8f6e5a
authored
Jan 18, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
session destroy
parent
6e987bfd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
71 deletions
+5
-71
controller.go
controller.go
+1
-0
router.go
router.go
+3
-1
sess_redis.go
session/redis/sess_redis.go
+1
-6
sess_redis_test.go
session/redis/sess_redis_test.go
+0
-64
No files found.
controller.go
View file @
fa8f6e5a
...
...
@@ -568,6 +568,7 @@ func (c *Controller) SessionRegenerateID() {
// DestroySession cleans session data and session cookie.
func
(
c
*
Controller
)
DestroySession
()
{
c
.
Ctx
.
Input
.
CruSession
.
Flush
()
c
.
Ctx
.
Input
.
CruSession
=
nil
GlobalSessions
.
SessionDestroy
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
}
...
...
router.go
View file @
fa8f6e5a
...
...
@@ -650,7 +650,9 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
return
}
defer
func
()
{
context
.
Input
.
CruSession
.
SessionRelease
(
rw
)
if
context
.
Input
.
CruSession
!=
nil
{
context
.
Input
.
CruSession
.
SessionRelease
(
rw
)
}
}()
}
...
...
session/redis/sess_redis.go
View file @
fa8f6e5a
...
...
@@ -98,18 +98,13 @@ func (rs *SessionStore) SessionID() string {
// SessionRelease save session values to redis
func
(
rs
*
SessionStore
)
SessionRelease
(
w
http
.
ResponseWriter
)
{
b
,
err
:=
session
.
EncodeGob
(
rs
.
values
)
if
err
!=
nil
{
return
}
c
:=
rs
.
p
.
Get
()
defer
c
.
Close
()
// Update session value if exists or error.
if
existed
,
err
:=
redis
.
Bool
(
c
.
Do
(
"EXISTS"
,
rs
.
sid
));
existed
||
err
!=
nil
{
c
.
Do
(
"SETEX"
,
rs
.
sid
,
rs
.
maxlifetime
,
string
(
b
))
}
c
.
Do
(
"SETEX"
,
rs
.
sid
,
rs
.
maxlifetime
,
string
(
b
))
}
// Provider redis session provider
...
...
session/redis/sess_redis_test.go
deleted
100644 → 0
View file @
6e987bfd
// Copyright 2016 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
redis
import
(
"testing"
)
func
TestSessionRelease
(
t
*
testing
.
T
)
{
provider
:=
Provider
{}
if
err
:=
provider
.
SessionInit
(
3
,
"127.0.0.1:6379"
);
err
!=
nil
{
t
.
Fatal
(
"init session err,"
,
err
)
}
sessionID
:=
"beegosessionid_00001"
session
,
err
:=
provider
.
SessionRegenerate
(
""
,
sessionID
)
if
err
!=
nil
{
t
.
Fatal
(
"new session error,"
,
err
)
}
// set item.
session
.
Set
(
"k1"
,
"v1"
)
// update.
session
.
SessionRelease
(
nil
)
session
,
err
=
provider
.
SessionRead
(
sessionID
)
if
err
!=
nil
{
t
.
Fatal
(
"read session error,"
,
err
)
}
if
v1
:=
session
.
Get
(
"k1"
);
v1
==
nil
{
t
.
Fatal
(
"want v1 got nil"
)
}
else
if
v
,
_
:=
v1
.
(
string
);
v
!=
"v1"
{
t
.
Fatalf
(
"want v1 got %s"
,
v
)
}
// delete
provider
.
SessionDestroy
(
sessionID
)
session
.
Set
(
"k2"
,
"v2"
)
session
.
SessionRelease
(
nil
)
session
,
err
=
provider
.
SessionRead
(
sessionID
)
if
err
!=
nil
{
t
.
Fatal
(
"read session error,"
,
err
)
}
if
session
.
Get
(
"k1"
)
!=
nil
||
session
.
Get
(
"k2"
)
!=
nil
{
t
.
Fatalf
(
"want emtpy session value,got %s,%s"
,
session
.
Get
(
"k1"
),
session
.
Get
(
"k2"
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment