update to new core session system

This commit is contained in:
Zeni Kim 2026-05-18 15:51:12 -05:00
parent f5ab92b1cf
commit df80e29f6e
5 changed files with 8 additions and 188 deletions

View file

@ -21,7 +21,7 @@ func AdminUsersList(c *core.Context) *core.Response {
// initiate authority
auth := new(utils.Authority)
var session = new(utils.SessionUser)
session := c.GetSession()
// true if session is active
hassession := session.Init(c)
@ -135,7 +135,7 @@ func AdminUsersAdd(c *core.Context) *core.Response {
// initiate authority
auth := new(utils.Authority)
var session = new(utils.SessionUser)
session := c.GetSession()
// true if session is active
hassession := session.Init(c)

View file

@ -19,7 +19,6 @@ import (
"git.smarteching.com/goffee/core"
"git.smarteching.com/goffee/cup/events"
"git.smarteching.com/goffee/cup/models"
"git.smarteching.com/goffee/cup/utils"
"github.com/google/uuid"
"gorm.io/gorm"
)
@ -101,7 +100,7 @@ func Signup(c *core.Context) *core.Response {
// cache the token
userAgent := c.GetUserAgent()
hashedCacheKey := utils.CreateAuthTokenHashedCacheKey(user.ID, userAgent)
hashedCacheKey := core.CreateAuthTokenHashedCacheKey(user.ID, userAgent)
err = c.GetCache().Set(hashedCacheKey, token)
if err != nil {
c.GetLogger().Error(err.Error())
@ -223,12 +222,12 @@ func Signin(c *core.Context) *core.Response {
}
// cache the token
userAgent := c.GetUserAgent()
hashedCacheKey := utils.CreateAuthTokenHashedCacheKey(user.ID, userAgent)
hashedCacheKey := core.CreateAuthTokenHashedCacheKey(user.ID, userAgent)
err = c.GetCache().Set(hashedCacheKey, token)
// delete data from old sessions
sessionKey := fmt.Sprintf("sess_%v", userAgent)
hashedSessionKey := utils.CreateAuthTokenHashedCacheKey(user.ID, sessionKey)
hashedSessionKey := core.CreateAuthTokenHashedCacheKey(user.ID, sessionKey)
_ = c.GetCache().Delete(hashedSessionKey)
if err != nil {
@ -463,7 +462,7 @@ func Signout(c *core.Context) *core.Response {
}))
}
userAgent := c.GetUserAgent()
hashedCacheKey := utils.CreateAuthTokenHashedCacheKey(uint(c.CastToInt(payload["userID"])), userAgent)
hashedCacheKey := core.CreateAuthTokenHashedCacheKey(uint(c.CastToInt(payload["userID"])), userAgent)
err = c.GetCache().Delete(hashedCacheKey)
if err != nil {