2016-05-09 10:11:05 +08:00
|
|
|
package sessions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/sessions"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Store the cookie store which is going to store session data in the cookie
|
|
|
|
var Store = sessions.NewCookieStore([]byte("secret-password"))
|
|
|
|
|
|
|
|
//IsLoggedIn will check if the user has an active session and return True
|
|
|
|
func IsLoggedIn(r *http.Request) bool {
|
2016-05-13 16:23:23 +08:00
|
|
|
session, err := Store.Get(r, "session")
|
|
|
|
if err == nil && (session.Values["loggedin"] == "true") {
|
2016-05-09 10:11:05 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|