core

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package core implements the central business logic of OzyBase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitOAuth added in v1.1.1

func InitOAuth() error

InitOAuth initializes the OAuth providers using gothic/goth

func SaveFile

func SaveFile(fileHeader *multipart.FileHeader, storageDir string) (string, error)

SaveFile saves a multipart file to the destination path with a unique name

Types

type AuditService added in v1.1.1

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

AuditService handles asynchronous log buffering and persistence.

func NewAuditService added in v1.1.1

func NewAuditService(db *data.DB) *AuditService

NewAuditService creates a new AuditService.

func (*AuditService) Log added in v1.1.1

func (s *AuditService) Log(log data.AuditLog)

Log adds a new log entry to the buffer.

func (*AuditService) Start added in v1.1.1

func (s *AuditService) Start()

Start spawns the background worker.

func (*AuditService) Stop added in v1.1.1

func (s *AuditService) Stop()

Stop gracefully shuts down the worker, flushing remaining logs.

type AuthLoginResult added in v1.1.1

type AuthLoginResult struct {
	Token       string `json:"token,omitempty"`
	MFAStore    string `json:"mfa_store,omitempty"` // Temporary identifier for MFA verification
	MFARequired bool   `json:"mfa_required"`
	User        *User  `json:"user"`
}

AuthLoginResult represents the outcome of a login attempt

type AuthService

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

func NewAuthService

func NewAuthService(db *data.DB, jwtSecret string, mailer mailer.Mailer) *AuthService

func (*AuthService) ConfirmPasswordReset added in v1.1.1

func (s *AuthService) ConfirmPasswordReset(ctx context.Context, token, newPassword string) error

ConfirmPasswordReset verifies the token and updates the user's password

func (*AuthService) DB added in v1.1.1

func (s *AuthService) DB() *data.DB

func (*AuthService) GenerateTokenForUser added in v1.1.1

func (s *AuthService) GenerateTokenForUser(ctx context.Context, userID, role, ip, ua string, isMFA bool) (string, error)

GenerateTokenForUser exposes internal token generation logic and creates a session

func (*AuthService) HandleOAuthLogin added in v1.1.1

func (s *AuthService) HandleOAuthLogin(ctx context.Context, provider, providerID, email string, data map[string]any) (string, *User, error)

HandleOAuthLogin handles authentication via external providers

func (*AuthService) ListSessions added in v1.1.1

func (s *AuthService) ListSessions(ctx context.Context, userID string) ([]Session, error)

ListSessions returns all active sessions for a user

func (*AuthService) Login

func (s *AuthService) Login(ctx context.Context, email, password string) (*AuthLoginResult, error)

Login verifies credentials and returns a AuthLoginResult

func (*AuthService) RequestPasswordReset added in v1.1.1

func (s *AuthService) RequestPasswordReset(ctx context.Context, email string) (string, error)

RequestPasswordReset generates a reset token and saves it

func (*AuthService) RevokeSession added in v1.1.1

func (s *AuthService) RevokeSession(ctx context.Context, sessionID, userID string) error

RevokeSession deletes a session

func (*AuthService) Signup

func (s *AuthService) Signup(ctx context.Context, email, password string) (*User, error)

Signup handles user registration

func (*AuthService) UpdateUserRole added in v1.1.1

func (s *AuthService) UpdateUserRole(ctx context.Context, userID, newRole string) error

UpdateUserRole updates a user's role

func (*AuthService) VerifyEmail added in v1.1.1

func (s *AuthService) VerifyEmail(ctx context.Context, token string) error

VerifyEmail marks a user as verified if the token is valid

type FileInfo added in v1.1.1

type FileInfo struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
	Path string `json:"path"`
}

FileInfo represents basic file metadata

func ListFiles added in v1.1.1

func ListFiles(storageDir string) ([]FileInfo, error)

ListFiles returns a list of files in the storage directory

type GeoInfo added in v1.1.1

type GeoInfo struct {
	Country string  `json:"country"`
	City    string  `json:"city"`
	Lat     float64 `json:"lat"`
	Lon     float64 `json:"lon"`
}

type GeoPolicy added in v1.1.1

type GeoPolicy struct {
	Enabled          bool     `json:"enabled"`
	AllowedCountries []string `json:"allowed_countries"`
}

type GeoService added in v1.1.1

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

func NewGeoService added in v1.1.1

func NewGeoService(db *data.DB) *GeoService

func (*GeoService) CheckBreach added in v1.1.1

func (s *GeoService) CheckBreach(ctx context.Context, ip string, country string) (bool, error)

func (*GeoService) GetLocation added in v1.1.1

func (s *GeoService) GetLocation(ctx context.Context, ip string) (GeoInfo, error)

func (*GeoService) GetPolicy added in v1.1.1

func (s *GeoService) GetPolicy(ctx context.Context) (*GeoPolicy, error)

func (*GeoService) InvalidatePolicy added in v1.1.1

func (s *GeoService) InvalidatePolicy()

type OAuthUser added in v1.1.1

type OAuthUser struct {
	ID        string
	Email     string
	Name      string
	AvatarURL string
	Provider  string
}

GetProviderUser common interface for OAuth users

type Session added in v1.1.1

type Session struct {
	ID            string    `json:"id"`
	UserID        string    `json:"user_id"`
	IPAddress     string    `json:"ip_address"`
	UserAgent     string    `json:"user_agent"`
	IsMFAVerified bool      `json:"is_mfa_verified"`
	ExpiresAt     time.Time `json:"expires_at"`
	CreatedAt     time.Time `json:"created_at"`
	LastUsedAt    time.Time `json:"last_used_at"`
}

Session represents an active user login session

type TwoFactorService added in v1.1.1

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

func NewTwoFactorService added in v1.1.1

func NewTwoFactorService(db *data.DB) *TwoFactorService

func (*TwoFactorService) DisableTwoFactor added in v1.1.1

func (s *TwoFactorService) DisableTwoFactor(ctx context.Context, userID string) error

DisableTwoFactor disables 2FA for a user

func (*TwoFactorService) EnableTwoFactor added in v1.1.1

func (s *TwoFactorService) EnableTwoFactor(ctx context.Context, userID, code string) error

EnableTwoFactor enables 2FA after user verifies the code

func (*TwoFactorService) GenerateSecret added in v1.1.1

func (s *TwoFactorService) GenerateSecret(ctx context.Context, userID, email string) (*TwoFactorSetup, error)

GenerateSecret creates a new TOTP secret for a user

func (*TwoFactorService) IsEnabled added in v1.1.1

func (s *TwoFactorService) IsEnabled(ctx context.Context, userID string) (bool, error)

IsEnabled checks if 2FA is enabled for a user

func (*TwoFactorService) VerifyCode added in v1.1.1

func (s *TwoFactorService) VerifyCode(ctx context.Context, userID, code string) (bool, error)

VerifyCode validates a TOTP code or backup code

type TwoFactorSetup added in v1.1.1

type TwoFactorSetup struct {
	Secret      string   `json:"secret"`
	QRCodeURL   string   `json:"qr_code_url"`
	BackupCodes []string `json:"backup_codes"`
}

type User

type User struct {
	ID           string    `json:"id"`
	Email        string    `json:"email"`
	PasswordHash string    `json:"-"`    // Never return in JSON
	Role         string    `json:"role"` // 'admin' or 'user'
	IsVerified   bool      `json:"is_verified"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

User represents a system user or admin

type Workspace added in v1.1.1

type Workspace struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	Config    any       `json:"config"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Workspace represents an isolated project environment

type WorkspaceMember added in v1.1.1

type WorkspaceMember struct {
	WorkspaceID string    `json:"workspace_id"`
	UserID      string    `json:"user_id"`
	Role        string    `json:"role"`
	JoinedAt    time.Time `json:"joined_at"`
}

WorkspaceMember links users to workspaces with a role

type WorkspaceService added in v1.1.1

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

func NewWorkspaceService added in v1.1.1

func NewWorkspaceService(db *data.DB) *WorkspaceService

func (*WorkspaceService) AddWorkspaceMember added in v1.1.1

func (s *WorkspaceService) AddWorkspaceMember(ctx context.Context, workspaceID, userID, role string) error

AddWorkspaceMember adds or updates a member's role in a workspace

func (*WorkspaceService) CreateWorkspace added in v1.1.1

func (s *WorkspaceService) CreateWorkspace(ctx context.Context, name, ownerID string) (*Workspace, error)

CreateWorkspace creates a new isolated environment and assigns an owner

func (*WorkspaceService) DeleteWorkspace added in v1.1.1

func (s *WorkspaceService) DeleteWorkspace(ctx context.Context, id string) error

DeleteWorkspace removes a workspace and all its members

func (*WorkspaceService) GenerateSlug added in v1.1.1

func (s *WorkspaceService) GenerateSlug(name string) string

GenerateSlug creates a URL-friendly version of the name

func (*WorkspaceService) GetDB added in v1.1.1

func (s *WorkspaceService) GetDB() *data.DB

func (*WorkspaceService) GetWorkspaceMembers added in v1.1.1

func (s *WorkspaceService) GetWorkspaceMembers(ctx context.Context, workspaceID string) ([]map[string]interface{}, error)

GetWorkspaceMembers returns all members of a workspace

func (*WorkspaceService) IsMember added in v1.1.1

func (s *WorkspaceService) IsMember(ctx context.Context, workspaceID, userID string) (bool, string, error)

IsMember checks if a user belongs to a workspace

func (*WorkspaceService) ListWorkspacesForUser added in v1.1.1

func (s *WorkspaceService) ListWorkspacesForUser(ctx context.Context, userID string) ([]Workspace, error)

ListWorkspacesForUser returns all workspaces where the user is a member

func (*WorkspaceService) RemoveWorkspaceMember added in v1.1.1

func (s *WorkspaceService) RemoveWorkspaceMember(ctx context.Context, workspaceID, userID string) error

RemoveWorkspaceMember removes a member from a workspace

func (*WorkspaceService) UpdateWorkspace added in v1.1.1

func (s *WorkspaceService) UpdateWorkspace(ctx context.Context, id, name string, config map[string]interface{}) error

UpdateWorkspace updates workspace metadata

Jump to

Keyboard shortcuts

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