mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-13 17:10:36 +00:00
Fixed session_rid in funcspec
This commit is contained in:
parent
1baa0af0ac
commit
4e2fe33b77
@ -758,8 +758,10 @@ func (h *Handler) replaceMetaVariables(sqlquery string, r *http.Request, userCtx
|
||||
}
|
||||
|
||||
if strings.Contains(sqlquery, "[rid_session]") {
|
||||
sessionID, _ := strconv.ParseInt(userCtx.SessionID, 10, 64)
|
||||
sqlquery = strings.ReplaceAll(sqlquery, "[rid_session]", fmt.Sprintf("%d", sessionID))
|
||||
sqlquery = strings.ReplaceAll(sqlquery, "[rid_session]", fmt.Sprintf("%d", userCtx.SessionRID))
|
||||
}
|
||||
if strings.Contains(sqlquery, "[id_session]") {
|
||||
sqlquery = strings.ReplaceAll(sqlquery, "[id_session]", userCtx.SessionID)
|
||||
}
|
||||
|
||||
if strings.Contains(sqlquery, "[method]") {
|
||||
|
||||
@ -7,15 +7,16 @@ import (
|
||||
|
||||
// UserContext holds authenticated user information
|
||||
type UserContext struct {
|
||||
UserID int `json:"user_id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserLevel int `json:"user_level"`
|
||||
SessionID string `json:"session_id"`
|
||||
RemoteID string `json:"remote_id"`
|
||||
Roles []string `json:"roles"`
|
||||
Email string `json:"email"`
|
||||
Claims map[string]any `json:"claims"`
|
||||
Meta map[string]any `json:"meta"` // Additional metadata that can hold any JSON-serializable values
|
||||
UserID int `json:"user_id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserLevel int `json:"user_level"`
|
||||
SessionID string `json:"session_id"`
|
||||
SessionRID int64 `json:"session_rid"`
|
||||
RemoteID string `json:"remote_id"`
|
||||
Roles []string `json:"roles"`
|
||||
Email string `json:"email"`
|
||||
Claims map[string]any `json:"claims"`
|
||||
Meta map[string]any `json:"meta"` // Additional metadata that can hold any JSON-serializable values
|
||||
}
|
||||
|
||||
// LoginRequest contains credentials for login
|
||||
|
||||
@ -3,6 +3,7 @@ package security
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// contextKey is a custom type for context keys to avoid collisions
|
||||
@ -14,6 +15,7 @@ const (
|
||||
UserNameKey contextKey = "user_name"
|
||||
UserLevelKey contextKey = "user_level"
|
||||
SessionIDKey contextKey = "session_id"
|
||||
SessionRIDKey contextKey = "session_rid"
|
||||
RemoteIDKey contextKey = "remote_id"
|
||||
UserRolesKey contextKey = "user_roles"
|
||||
UserEmailKey contextKey = "user_email"
|
||||
@ -58,6 +60,7 @@ func setUserContext(r *http.Request, userCtx *UserContext) *http.Request {
|
||||
ctx = context.WithValue(ctx, UserNameKey, userCtx.UserName)
|
||||
ctx = context.WithValue(ctx, UserLevelKey, userCtx.UserLevel)
|
||||
ctx = context.WithValue(ctx, SessionIDKey, userCtx.SessionID)
|
||||
ctx = context.WithValue(ctx, SessionRIDKey, userCtx.SessionRID)
|
||||
ctx = context.WithValue(ctx, RemoteIDKey, userCtx.RemoteID)
|
||||
ctx = context.WithValue(ctx, UserRolesKey, userCtx.Roles)
|
||||
|
||||
@ -220,6 +223,16 @@ func GetSessionID(ctx context.Context) (string, bool) {
|
||||
return sessionID, ok
|
||||
}
|
||||
|
||||
// GetSessionID extracts the session ID from context
|
||||
func GetSessionRID(ctx context.Context) (int64, bool) {
|
||||
sessionRIDStr, ok := ctx.Value(SessionRIDKey).(string)
|
||||
sessionRID, err := strconv.ParseInt(sessionRIDStr, 10, 64)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return sessionRID, ok
|
||||
}
|
||||
|
||||
// GetRemoteID extracts the remote ID from context
|
||||
func GetRemoteID(ctx context.Context) (string, bool) {
|
||||
remoteID, ok := ctx.Value(RemoteIDKey).(string)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user