anonymous

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// EnableAnonymous enables anonymous user creation
	EnableAnonymous bool `json:"enableAnonymous"`
	// SessionExpiryHours is the anonymous session expiry time in hours
	SessionExpiryHours int `json:"sessionExpiryHours"`
	// CleanupIntervalHours is how often to clean up expired anonymous users
	CleanupIntervalHours int `json:"cleanupIntervalHours"`
	// AutoConvert allows converting anonymous users to registered users
	AutoConvert bool `json:"autoConvert"`
}

Config holds the anonymous plugin configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default anonymous plugin configuration

type ErrorResponse

type ErrorResponse = responses.ErrorResponse

Response types - use shared responses from core

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(s *Service, authInst core.Authsome) *Handler
func (h *Handler) Link(c forge.Context) error

Link upgrades an anonymous session to a real account

func (*Handler) SignIn

func (h *Handler) SignIn(c forge.Context) error

SignIn creates a guest user and session

type LinkRequest

type LinkRequest struct {
	Email    string `json:"email" validate:"required,email" example:"user@example.com"`
	Password string `json:"password" validate:"required,min=8" example:"password123"`
	Name     string `json:"name" example:"John Doe"`
}

type LinkResponse

type LinkResponse struct {
	User    interface{} `json:"user"`
	Message string      `json:"message"`
}

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new anonymous plugin instance with optional configuration

func (*Plugin) ID

func (p *Plugin) ID() string

func (*Plugin) Init

func (p *Plugin) Init(authInst core.Authsome) error

Init accepts auth instance with GetDB method

func (*Plugin) Migrate

func (p *Plugin) Migrate() error

func (*Plugin) RegisterHooks

func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

RegisterRoutes registers Anonymous plugin routes

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the anonymous plugin

func WithAutoConvert

func WithAutoConvert(enable bool) PluginOption

WithAutoConvert sets whether auto-conversion is enabled

func WithCleanupIntervalHours

func WithCleanupIntervalHours(hours int) PluginOption

WithCleanupIntervalHours sets the cleanup interval

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithEnableAnonymous

func WithEnableAnonymous(enable bool) PluginOption

WithEnableAnonymous sets whether anonymous users are enabled

func WithSessionExpiryHours

func WithSessionExpiryHours(hours int) PluginOption

WithSessionExpiryHours sets the session expiry time

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides anonymous sign-in by creating a guest user and session

func NewService

func NewService(users *repo.UserRepository, sess *session.Service, config Config) *Service

func (*Service) GetUserByID

func (s *Service) GetUserByID(ctx context.Context, id xid.ID) (*coreuser.User, error)

GetUserByID is a helper to get a user by ID (returns DTO)

func (*Service) LinkGuest

func (s *Service) LinkGuest(ctx context.Context, token, email, password, name string) (*coreuser.User, error)

LinkGuest upgrades an anonymous guest account to a real account

func (*Service) SignInGuest

func (s *Service) SignInGuest(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ip, ua string) (*session.Session, error)

SignInGuest creates a guest user and returns a session token

type SignInRequest

type SignInRequest struct {
}

Request types

type SignInResponse

type SignInResponse struct {
	Token   string      `json:"token" example:"session_token_abc123"`
	Session interface{} `json:"session"`
	User    interface{} `json:"user"`
}

Plugin-specific responses

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL