Refactor session code
This commit is contained in:
@ -167,7 +167,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
storeSession := session.GlobalSessionStore.Create()
|
||||
storeSession := session.Create()
|
||||
storeSession.Values["user"] = types.User{
|
||||
UserID: user.UserID,
|
||||
Email: oauthUser.Email,
|
||||
|
@ -130,7 +130,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
delete(SetupUser, code)
|
||||
|
||||
storeSession := session.GlobalSessionStore.Create()
|
||||
storeSession := session.Create()
|
||||
storeSession.Values["user"] = types.User{
|
||||
UserID: userID,
|
||||
Email: unregisteredUser.Email,
|
||||
|
@ -4,25 +4,18 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
||||
func init() {
|
||||
log = logger.Logger()
|
||||
}
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("Session")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
storeSession, err := session.GlobalSessionStore.Get(cookie.Value)
|
||||
storeSession, err := session.Get(cookie.Value)
|
||||
if err != nil {
|
||||
if errors.Is(err, &session.SessionNotFoundError{}) {
|
||||
storeSession.Destroy(w)
|
||||
@ -31,7 +24,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
session.GlobalSessionStore.Delete(cookie.Value)
|
||||
storeSession.Delete()
|
||||
session.RemoveSessionInfo(storeSession.Values["user"].(types.User).Email, cookie.Value)
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
|
@ -58,7 +58,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if email == userData.Email && utils.CheckPasswordHash(password, userData.Password) {
|
||||
storeSession := session.GlobalSessionStore.Create()
|
||||
storeSession := session.Create()
|
||||
storeSession.Values["user"] = types.User{
|
||||
UserID: userData.UserID,
|
||||
Email: email,
|
||||
|
Reference in New Issue
Block a user