Documentation
¶
Overview ¶
Package core implements the central business logic of OzyBase.
Index ¶
- func InitOAuth() error
- func SaveFile(fileHeader *multipart.FileHeader, storageDir string) (string, error)
- type AuditService
- type AuthLoginResult
- type AuthService
- func (s *AuthService) ConfirmPasswordReset(ctx context.Context, token, newPassword string) error
- func (s *AuthService) DB() *data.DB
- func (s *AuthService) GenerateTokenForUser(ctx context.Context, userID, role, ip, ua string, isMFA bool) (string, error)
- func (s *AuthService) HandleOAuthLogin(ctx context.Context, provider, providerID, email string, data map[string]any) (string, *User, error)
- func (s *AuthService) ListSessions(ctx context.Context, userID string) ([]Session, error)
- func (s *AuthService) Login(ctx context.Context, email, password string) (*AuthLoginResult, error)
- func (s *AuthService) RequestPasswordReset(ctx context.Context, email string) (string, error)
- func (s *AuthService) RevokeSession(ctx context.Context, sessionID, userID string) error
- func (s *AuthService) Signup(ctx context.Context, email, password string) (*User, error)
- func (s *AuthService) UpdateUserRole(ctx context.Context, userID, newRole string) error
- func (s *AuthService) VerifyEmail(ctx context.Context, token string) error
- type FileInfo
- type GeoInfo
- type GeoPolicy
- type GeoService
- type OAuthUser
- type Session
- type TwoFactorService
- func (s *TwoFactorService) DisableTwoFactor(ctx context.Context, userID string) error
- func (s *TwoFactorService) EnableTwoFactor(ctx context.Context, userID, code string) error
- func (s *TwoFactorService) GenerateSecret(ctx context.Context, userID, email string) (*TwoFactorSetup, error)
- func (s *TwoFactorService) IsEnabled(ctx context.Context, userID string) (bool, error)
- func (s *TwoFactorService) VerifyCode(ctx context.Context, userID, code string) (bool, error)
- type TwoFactorSetup
- type User
- type Workspace
- type WorkspaceMember
- type WorkspaceService
- func (s *WorkspaceService) AddWorkspaceMember(ctx context.Context, workspaceID, userID, role string) error
- func (s *WorkspaceService) CreateWorkspace(ctx context.Context, name, ownerID string) (*Workspace, error)
- func (s *WorkspaceService) DeleteWorkspace(ctx context.Context, id string) error
- func (s *WorkspaceService) GenerateSlug(name string) string
- func (s *WorkspaceService) GetDB() *data.DB
- func (s *WorkspaceService) GetWorkspaceMembers(ctx context.Context, workspaceID string) ([]map[string]interface{}, error)
- func (s *WorkspaceService) IsMember(ctx context.Context, workspaceID, userID string) (bool, string, error)
- func (s *WorkspaceService) ListWorkspacesForUser(ctx context.Context, userID string) ([]Workspace, error)
- func (s *WorkspaceService) RemoveWorkspaceMember(ctx context.Context, workspaceID, userID string) error
- func (s *WorkspaceService) UpdateWorkspace(ctx context.Context, id, name string, config map[string]interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*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
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
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) 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
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 (*GeoService) GetLocation ¶ added in v1.1.1
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 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) VerifyCode ¶ added in v1.1.1
VerifyCode validates a TOTP code or backup code
type TwoFactorSetup ¶ added in v1.1.1
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