service

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommunicationConfig

type CommunicationConfig struct {
	ServiceEndpoint          string `yaml:"ServiceEndpoint"`
	EmailVerificationSubject string `yaml:"EmailVerificationSubject"`
	EmailVerificationBody    string `yaml:"EmailVerificationBody"`
	SMSVerificationMessage   string `yaml:"SMSVerificationMessage"`
}

func (*CommunicationConfig) Default

func (c *CommunicationConfig) Default()

type Config

type Config struct {
	JWT           JWTConfig           `yaml:"JWT"`
	Security      SecurityConfig      `yaml:"Security"`
	Communication CommunicationConfig `yaml:"Communication"`
}

func (*Config) Default

func (c *Config) Default()

type JWTConfig

type JWTConfig struct {
	SecretKey       string        `yaml:"SecretKey"`       // JWT signing secret key
	AccessTokenTTL  time.Duration `yaml:"AccessTokenTTL"`  // Access token expiration time
	RefreshTokenTTL time.Duration `yaml:"RefreshTokenTTL"` // Refresh token expiration time
}

func (*JWTConfig) Default

func (c *JWTConfig) Default()

func (*JWTConfig) GetSecretKey

func (c *JWTConfig) GetSecretKey() []byte

type Repository

type Repository interface {
	Ping(ctx context.Context) error

	// Permission methods
	CreatePermission(ctx context.Context, permission *dao.Permission) (*dao.Permission, error)
	GetPermissionByID(ctx context.Context, id int64) (*dao.Permission, error)
	ListPermissions(ctx context.Context, filters *filter.PermissionFilter) ([]*dao.Permission, error)
	UpdatePermission(ctx context.Context, id int64, updates map[string]interface{}) (*dao.Permission, error)
	DeletePermission(ctx context.Context, id int64) error
	GetPermissionByName(ctx context.Context, name string) (*dao.Permission, error)

	// User methods
	CreateUser(ctx context.Context, user *dao.User) (*dao.User, error)
	CreateUserProfile(ctx context.Context, profile *dao.Profile) (*dao.Profile, error)
	GetUserByID(ctx context.Context, id int64) (*dao.User, error)
	GetUserByUUID(ctx context.Context, uuid string) (*dao.User, error)
	GetUserByUsername(ctx context.Context, username string) (*dao.User, error)
	GetUserByEmail(ctx context.Context, email string) (*dao.User, error)
	GetUserByPhone(ctx context.Context, identifier string) (*dao.User, error)
	GetUserProfile(ctx context.Context, userID int64) (*dao.Profile, error)
	UpdateUser(ctx context.Context, id int64, updates map[string]interface{}) (*dao.User, error)
	UpdateUserProfile(ctx context.Context, userID int64, updates map[string]interface{}) (*dao.Profile, error)
	DeleteUser(ctx context.Context, id int64, softDelete bool) error
	ListUsers(ctx context.Context, filters *filter.UserFilter) ([]*dao.User, error)
	CheckUsernameExists(ctx context.Context, username string) (bool, error)
	CheckEmailExists(ctx context.Context, email string) (bool, error)

	// Profile management methods
	ListUserProfiles(ctx context.Context, filters *filter.UserProfilesFilter) ([]*dao.Profile, error)
	ListUserProfileUUIDs(ctx context.Context, userID int64) ([]uuid.UUID, error)
	GetProfileByUUID(ctx context.Context, uuid string) (*dao.Profile, error)
	UpdateProfileByUUID(ctx context.Context, uuid string, updates map[string]interface{}) (*dao.Profile, error)
	CountUserProfiles(ctx context.Context, userUUID string) (int32, error)
	DeleteProfileByUUID(ctx context.Context, uuid string) error

	// Verification methods
	CreateOTPVerification(ctx context.Context, otp *dao.OTPVerification) error
	GetOTPVerification(ctx context.Context, identifier, code string) (*dao.OTPVerification, error)
	UpdateVerificationStatus(ctx context.Context, userID int64, field string, verified bool) error
	DeleteOTPVerification(ctx context.Context, identifier, otpType string) error

	// Session management methods
	CreateSession(ctx context.Context, session *dao.Session) (*dao.Session, error)
	GetSessionByToken(ctx context.Context, sessionToken string) (*dao.Session, error)
	GetSessionByUUID(ctx context.Context, sessionUUID string) (*dao.Session, error)
	GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*dao.Session, error)
	UpdateSession(ctx context.Context, sessionUUID string, updates map[string]interface{}) (*dao.Session, error)
	DeleteSession(ctx context.Context, sessionUUID string) error
	DeleteUserSessions(ctx context.Context, userUUID string) error
	ListUserSessions(ctx context.Context, filters *filter.UserSessionsFilter) ([]*dao.Session, error)
	UpdateLastActivity(ctx context.Context, sessionUUID string) error

	// Group methods
	CreateGroup(ctx context.Context, group *dao.Group) (*dao.Group, error)
	GetGroupByID(ctx context.Context, id int64) (*dao.Group, error)
	GetGroupByUUID(ctx context.Context, uuid string) (*dao.Group, error)
	GetGroupByName(ctx context.Context, name string) (*dao.Group, error)
	ListGroups(ctx context.Context, filters *filter.GroupFilter) ([]*dao.Group, error)
	UpdateGroup(ctx context.Context, id int64, updates map[string]interface{}) (*dao.Group, error)
	DeleteGroup(ctx context.Context, id int64) error
	CheckGroupNameExists(ctx context.Context, name string) (bool, error)

	// Group membership methods
	AssignUserToGroup(ctx context.Context, userID, groupID int64, assignedBy int64, expiresAt *int64) error
	AssignUsersToGroup(ctx context.Context, userIDs []int64, groupID int64, assignedBy int64, expiresAt *int64) error
	RemoveUserFromGroup(ctx context.Context, userID, groupID int64) error
	RemoveUsersFromGroup(ctx context.Context, userIDs []int64, groupID int64) error
	ListGroupUsers(ctx context.Context, filters *filter.GroupUsersFilter) ([]*dao.User, error)
	ListUserGroups(ctx context.Context, filters *filter.UserGroupsFilter) ([]*dao.Group, error)
	IsUserInGroup(ctx context.Context, userID, groupID int64) (bool, error)

	// Group permission methods
	AssignPermissionToGroup(ctx context.Context, groupID, permissionID, grantedBy int64) error
	AssignPermissionsToGroup(ctx context.Context, groupID int64, permissionIDs []int64, grantedBy int64) error
	RemovePermissionFromGroup(ctx context.Context, groupID, permissionID int64) error
	RemovePermissionsFromGroup(ctx context.Context, groupID int64, permissionIDs []int64) error
	ListGroupPermissions(ctx context.Context, groupId int64) ([]*dao.EffectivePermission, error)
	IsPermissionAssignedToGroup(ctx context.Context, groupID, permissionID int64) (bool, error)

	// User permission methods
	AssignPermissionToUser(ctx context.Context, userID, permissionID, grantedBy int64, expiresAt *int64) error
	AssignPermissionsToUser(ctx context.Context, userID int64, permissionIDs []int64, grantedBy int64, expiresAt *int64) error
	RemovePermissionFromUser(ctx context.Context, userID, permissionID int64) error
	RemovePermissionsFromUser(ctx context.Context, userID int64, permissionIDs []int64) error
	ListUserPermissions(ctx context.Context, userId int64) ([]*dao.EffectivePermission, error)
	GetUserEffectivePermissions(ctx context.Context, userId int64) ([]*dao.EffectivePermission, error)
	IsPermissionAssignedToUser(ctx context.Context, userID, permissionID int64) (bool, error)
	GetUserEffectivePermissionNames(ctx context.Context, userId int64) ([]string, error)
	// Stats methods
	GetTotalUsers(ctx context.Context) (int64, error)
	GetTotalPermissions(ctx context.Context) (int64, error)
	GetTotalGroups(ctx context.Context) (int64, error)
	GetActiveUsers(ctx context.Context) (int64, error)

	// Config Entity methods
	CreateConfigEntity(ctx context.Context, entity *dao.ConfigEntity) error
	GetConfigEntityByID(ctx context.Context, id int64) (*dao.ConfigEntity, error)
	GetConfigEntityByName(ctx context.Context, name string) (*dao.ConfigEntity, error)
	ListConfigEntities(ctx context.Context, filters *filter.ConfigEntityFilter) ([]*dao.ConfigEntity, error)
	UpdateConfigEntity(ctx context.Context, id int64, updates map[string]interface{}) error
	DeleteConfigEntity(ctx context.Context, id int64) error

	// Config methods
	CreateConfig(ctx context.Context, config *dao.Config) error
	GetConfigByID(ctx context.Context, id int64) (*dao.Config, error)
	GetConfigByEntityAndKey(ctx context.Context, entityID int64, key string) (*dao.Config, error)
	GetConfigByEntityNameAndKey(ctx context.Context, entityName, key string) (*dao.Config, error)
	ListConfigs(ctx context.Context, filters *filter.ConfigFilter) ([]*dao.Config, error)
	UpdateConfig(ctx context.Context, id int64, updates map[string]interface{}) error
	DeleteConfig(ctx context.Context, id int64) error
	GetConfigsByEntityAndKeys(ctx context.Context, entityID int64, keys []string) (map[string]*dao.Config, error)
	GetConfigsByEntityNameAndKeys(ctx context.Context, entityName string, keys []string) (map[string]*dao.Config, error)
}

type SecurityConfig

type SecurityConfig struct {
	BcryptCost       int           `yaml:"BcryptCost"`       // Password hashing cost
	MaxLoginAttempts int           `yaml:"MaxLoginAttempts"` // Maximum failed login attempts
	LockoutDuration  time.Duration `yaml:"LockoutDuration"`  // Account lockout duration
}

func (*SecurityConfig) Default

func (c *SecurityConfig) Default()

type Service

type Service struct {
	openauth_v1.UnimplementedOpenAuthServer
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, cfg *Config, repo Repository) *Service

func (*Service) AssignPermissionsToGroup

AssignPermissionsToGroup assigns multiple permissions to a group

func (*Service) AssignPermissionsToUser

AssignPermissionsToUser assigns multiple permissions directly to a user

func (*Service) AssignUsersToGroup

AssignUserToGroup adds a user to a group

func (*Service) ChangePassword

ChangePassword allows users to change their password

func (*Service) CheckEmail

CheckEmail checks if an email address is available for registration

func (*Service) CheckUsername

CheckUsername checks if a username is available for registration

func (*Service) CreateConfig

CreateConfig creates a new configuration

func (*Service) CreateConfigEntity

CreateConfigEntity creates a new config entity

func (*Service) CreateGroup

CreateGroup creates a new group in the system

func (*Service) CreatePermission

CreatePermission creates a new permission

func (*Service) CreateProfile

CreateProfile creates a new profile for a user

func (*Service) DeleteConfig

DeleteConfig deletes a config

func (*Service) DeleteConfigEntity

DeleteConfigEntity deletes a config entity

func (*Service) DeleteGroup

DeleteGroup removes a group from the system

func (*Service) DeletePermission

DeletePermission deletes a permission

func (*Service) DeleteProfile

DeleteProfile removes a specific profile

func (*Service) DeleteUser

DeleteUser removes or deactivates a user account

func (*Service) GetConfig

GetConfig retrieves a config by ID

func (*Service) GetConfigEntity

GetConfigEntity retrieves a config entity by ID

func (*Service) GetConfigsByKeys

GetConfigsByKeys retrieves multiple configs by keys within an entity

func (*Service) GetGroup

GetGroup retrieves a group by ID, UUID, or name

func (*Service) GetPermission

GetPermission retrieves a permission by ID

func (*Service) GetUser

GetUser retrieves user information by ID, UUID, username, or email

func (*Service) GetUserEffectivePermissions

GetUserEffectivePermissions retrieves all effective permissions for a user

func (*Service) ListConfigEntities

ListConfigEntities lists config entities with filtering and pagination

func (*Service) ListConfigs

ListConfigs lists configs with filtering and pagination

func (*Service) ListGroupPermissions

ListGroupPermissions retrieves permissions assigned to a group

func (*Service) ListGroupUsers

ListGroupUsers retrieves all users in a specific group

func (*Service) ListGroups

ListGroups retrieves groups with filtering and pagination

func (*Service) ListPermissions

ListPermissions retrieves permissions with filtering and pagination

func (*Service) ListUserGroups

ListUserGroups retrieves all groups for a specific user

func (*Service) ListUserPermissions

ListUserPermissions retrieves permissions directly assigned to a user

func (*Service) ListUserProfiles

ListUserProfiles retrieves all profiles for a user

func (*Service) ListUserSessions

ListUserSessions retrieves active sessions for a user

func (*Service) ListUsers

ListUsers retrieves users with filtering, sorting, and pagination

func (*Service) Logout

Logout terminates user session(s)

func (*Service) Ping

func (*Service) RefreshToken

RefreshToken generates new access token using refresh token

func (*Service) RemovePermissionsFromGroup

RemovePermissionsFromGroup removes multiple permissions from a group

func (*Service) RemovePermissionsFromUser

RemovePermissionsFromUser removes multiple permissions directly assigned to a user

func (*Service) RemoveUsersFromGroup

RemoveUsersFromGroup removes multiple users from a group

func (*Service) SendVerificationCode

SendVerificationCode implements openauth_v1.OpenAuthServer.

func (*Service) SignIn

SignIn authenticates a user and creates a new session

func (*Service) SignUp

SignUp creates a new user account in the system

func (*Service) Stats

Stats returns system statistics

func (*Service) TerminateSession

TerminateSession ends a specific user session

func (*Service) UpdateConfig

UpdateConfig updates an existing config

func (*Service) UpdateConfigEntity

UpdateConfigEntity updates an existing config entity

func (*Service) UpdateGroup

UpdateGroup modifies an existing group

func (*Service) UpdatePermission

UpdatePermission updates an existing permission

func (*Service) UpdateProfile

UpdateProfile modifies an existing profile

func (*Service) UpdateUser

UpdateUser modifies user account and profile information

func (*Service) ValidateAccessToken

func (s *Service) ValidateAccessToken(tokenString string) (*jwtutils.JWTClaims, error)

ValidateAccessToken parses and validates a JWT access token

func (*Service) ValidateToken

ValidateToken checks if an access token is valid

func (*Service) VerifyEmail

VerifyEmail verifies a user's email address using a verification code

func (*Service) VerifyPhone

VerifyPhone verifies a user's phone number using a verification code

Jump to

Keyboard shortcuts

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