services

package
v0.0.0-...-52b6450 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmail        = errors.New("invalid email format")
	ErrEmailExists         = errors.New("email already exists")
	ErrPasswordTooShort    = errors.New("password must be at least 8 characters")
	ErrPasswordTooLong     = errors.New("password must be at most 128 characters")
	ErrPasswordNoUppercase = errors.New("password must contain at least one uppercase letter")
	ErrPasswordNoLowercase = errors.New("password must contain at least one lowercase letter")
	ErrPasswordNoNumber    = errors.New("password must contain at least one number")
	ErrPasswordNoSpecial   = errors.New("password must contain at least one special character")
	ErrPasswordsDontMatch  = errors.New("passwords do not match")
	ErrNameTooShort        = errors.New("name must be at least 2 characters")
	ErrNameTooLong         = errors.New("name must be at most 100 characters")
	ErrUserInactive        = errors.New("user account is inactive")
)

Validation errors

View Source
var DB *gorm.DB

DB est l'instance globale maintenue pour la compatibilité avec le code existant Deprecated: Utiliser DatabaseService via le contexte ou injection de dépendances

Functions

func CloseDB

func CloseDB() error

CloseDB ferme la connexion à la base de données (compatibilité legacy) Deprecated: Utiliser DatabaseService.Close() à la place

func ExtractTokenFromRequest

func ExtractTokenFromRequest(c interface{}) (string, error)

ExtractTokenFromRequest extrait le token d'accès d'une requête

func GenerateCodeChallenge

func GenerateCodeChallenge(codeVerifier string) (string, error)

GenerateCodeChallenge génère un code challenge pour PKCE

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString génère une chaîne aléatoire sécurisée

func InitDB

func InitDB(dsn string) error

InitDB initialise la connexion à la base de données (compatibilité legacy) Deprecated: Utiliser NewDatabaseService à la place

func NewDatabaseService

func NewDatabaseService(dsn string) (interfaces.IDatabaseService, error)

NewDatabaseService crée une nouvelle instance du service de base de données

func ParseScopes

func ParseScopes(scopeString string) []string

ParseScopes parse une chaîne de scopes en tableau

func SanitizeEmail

func SanitizeEmail(email string) string

SanitizeEmail nettoie et normalise l'email

func SanitizeName

func SanitizeName(name string) string

SanitizeName nettoie le nom

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail vérifie le format de l'email

func ValidateName

func ValidateName(name string) error

ValidateName vérifie la validité du nom

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword vérifie la complexité du mot de passe

func ValidateRegistrationInput

func ValidateRegistrationInput(name, email, password, confirmPassword string) error

ValidateRegistrationInput valide toutes les entrées d'inscription

Types

type DomainService

type DomainService struct {
	DB *gorm.DB
}

DomainService gère les opérations liées aux domaines

func NewDomainService

func NewDomainService(db *gorm.DB) *DomainService

NewDomainService crée une nouvelle instance de DomainService

func (*DomainService) AddUserToDomain

func (s *DomainService) AddUserToDomain(domainID string, userID string, isAdmin bool, isOwner bool) error

AddUserToDomain ajoute un utilisateur à un domaine

func (*DomainService) CreateDomain

func (s *DomainService) CreateDomain(domain *model.Domain) error

CreateDomain crée un nouveau domaine

func (*DomainService) CreateDomainSettings

func (s *DomainService) CreateDomainSettings(settings *model.DomainSettings) error

CreateDomainSettings crée ou met à jour les paramètres d'un domaine

func (*DomainService) DeleteDomain

func (s *DomainService) DeleteDomain(id string) error

DeleteDomain supprime un domaine

func (*DomainService) GetDomainByID

func (s *DomainService) GetDomainByID(id string) (*model.Domain, error)

GetDomainByID récupère un domaine par son ID

func (*DomainService) GetDomainByName

func (s *DomainService) GetDomainByName(name string) (*model.Domain, error)

GetDomainByName récupère un domaine par son nom

func (*DomainService) GetDomainSettings

func (s *DomainService) GetDomainSettings(domainID string) (*model.DomainSettings, error)

GetDomainSettings récupère les paramètres d'un domaine

func (*DomainService) GetDomainUserCount

func (s *DomainService) GetDomainUserCount(domainID string) (int, error)

GetDomainUserCount récupère le nombre d'utilisateurs d'un domaine

func (*DomainService) GetDomainWithDetails

func (s *DomainService) GetDomainWithDetails(domainID string) (*model.DomainWithDetails, error)

GetDomainWithDetails récupère un domaine avec ses informations détaillées

func (*DomainService) GetDomainsForUser

func (s *DomainService) GetDomainsForUser(userID string) ([]model.Domain, error)

GetDomainsForUser récupère les domaines d'un utilisateur

func (*DomainService) GetUsersByDomain

func (s *DomainService) GetUsersByDomain(domainID string) ([]model.User, error)

GetUsersByDomain récupère les utilisateurs d'un domaine

func (*DomainService) InitializeDefaultDomains

func (s *DomainService) InitializeDefaultDomains() error

InitializeDefaultDomains initialise les domaines par défaut

func (*DomainService) IsDomainActive

func (s *DomainService) IsDomainActive(domainName string) (bool, error)

IsDomainActive vérifie si un domaine est actif

func (*DomainService) IsEmailFromManagedDomain

func (s *DomainService) IsEmailFromManagedDomain(email string) (bool, *model.Domain, error)

IsEmailFromManagedDomain vérifie si une adresse email appartient à un domaine géré

func (*DomainService) IsUserDomainAdmin

func (s *DomainService) IsUserDomainAdmin(userID string, domainID string) (bool, error)

IsUserDomainAdmin vérifie si un utilisateur est administrateur d'un domaine

func (*DomainService) IsUserDomainOwner

func (s *DomainService) IsUserDomainOwner(userID string, domainID string) (bool, error)

IsUserDomainOwner vérifie si un utilisateur est propriétaire d'un domaine

func (*DomainService) ListDomains

func (s *DomainService) ListDomains() ([]model.Domain, error)

ListDomains liste tous les domaines

func (*DomainService) ListDomainsByOrganization

func (s *DomainService) ListDomainsByOrganization(orgID string) ([]model.Domain, error)

ListDomainsByOrganization liste les domaines par organisation

func (*DomainService) RemoveUserFromDomain

func (s *DomainService) RemoveUserFromDomain(domainID string, userID string) error

RemoveUserFromDomain retire un utilisateur d'un domaine

func (*DomainService) UpdateDomain

func (s *DomainService) UpdateDomain(domain *model.Domain) error

UpdateDomain met à jour un domaine

func (*DomainService) VerifyDomain

func (s *DomainService) VerifyDomain(domainID string, method string, value string) error

VerifyDomain vérifie un domaine

type EmailService

type EmailService struct {
	DB *gorm.DB
}

EmailService gère les opérations liées aux emails et tokens

func NewEmailService

func NewEmailService(db *gorm.DB) *EmailService

NewEmailService crée une nouvelle instance de EmailService

func (*EmailService) CreateEmailVerification

func (s *EmailService) CreateEmailVerification(userID string, email string) (*model.EmailVerificationToken, error)

CreateEmailVerification crée un token de vérification d'email

func (*EmailService) CreatePasswordReset

func (s *EmailService) CreatePasswordReset(email string) (*model.PasswordResetToken, error)

CreatePasswordReset crée un token de réinitialisation de mot de passe

func (*EmailService) CreateRefreshToken

func (s *EmailService) CreateRefreshToken(userID string, token string) (*model.OAuthRefreshToken, error)

CreateRefreshToken creates a refresh token for a user

func (*EmailService) GenerateToken

func (s *EmailService) GenerateToken() (string, error)

GenerateToken génère un token aléatoire sécurisé

func (*EmailService) ResetPassword

func (s *EmailService) ResetPassword(token, newPassword string) error

ResetPassword réinitialise le mot de passe avec un token

func (*EmailService) RevokeRefreshToken

func (s *EmailService) RevokeRefreshToken(token string) error

RevokeRefreshToken marks a refresh token as revoked

func (*EmailService) SendEmailVerificationEmail

func (s *EmailService) SendEmailVerificationEmail(email, token string) error

SendEmailVerificationEmail envoie un email de vérification (simulation)

func (*EmailService) SendPasswordResetEmail

func (s *EmailService) SendPasswordResetEmail(email, token string) error

SendPasswordResetEmail envoie un email de réinitialisation (simulation)

func (*EmailService) ValidateRefreshToken

func (s *EmailService) ValidateRefreshToken(token string) (*model.OAuthRefreshToken, error)

ValidateRefreshToken validates a refresh token

func (*EmailService) VerifyEmail

func (s *EmailService) VerifyEmail(token string) (*model.User, error)

VerifyEmail vérifie un email avec un token

type ExternalAuthService

type ExternalAuthService struct {
	DB         *gorm.DB
	Config     *config.OAuthProvidersConfig
	EncryptKey []byte
}

ExternalAuthService gère l'authentification via des providers externes

func NewExternalAuthService

func NewExternalAuthService(db *gorm.DB, encryptKey string) *ExternalAuthService

NewExternalAuthService crée une nouvelle instance du service

func (*ExternalAuthService) AutoMigrateExternalAccounts

func (s *ExternalAuthService) AutoMigrateExternalAccounts() error

AutoMigrateExternalAccounts exécute la migration automatique si nécessaire Cette fonction peut être appelée au démarrage de l'application

func (*ExternalAuthService) CleanupExpiredStates

func (s *ExternalAuthService) CleanupExpiredStates() error

CleanupExpiredStates nettoie les states OAuth expirés

func (*ExternalAuthService) ExchangeCode

func (s *ExternalAuthService) ExchangeCode(provider, code string) (*TokenExchangeResult, error)

ExchangeCode échange le code OAuth contre des tokens

func (*ExternalAuthService) FindOrCreateUser

func (s *ExternalAuthService) FindOrCreateUser(provider string, userInfo *model.ProviderUserInfo) (*model.User, bool, error)

FindOrCreateUser trouve ou crée un utilisateur à partir des infos OAuth

func (*ExternalAuthService) GenerateOAuthURL

func (s *ExternalAuthService) GenerateOAuthURL(provider, action string, userID *uint) (string, string, error)

GenerateOAuthURL génère l'URL d'authentification pour un provider

func (*ExternalAuthService) GetMigrationStatus

func (s *ExternalAuthService) GetMigrationStatus() map[string]interface{}

GetMigrationStatus retourne le statut de la migration Discord

func (*ExternalAuthService) GetUserExternalAccounts

func (s *ExternalAuthService) GetUserExternalAccounts(userID uint) ([]*model.ExternalAccountResponse, error)

GetUserExternalAccounts récupère tous les comptes externes d'un utilisateur

func (*ExternalAuthService) GetUserInfo

func (s *ExternalAuthService) GetUserInfo(provider, accessToken string) (*model.ProviderUserInfo, error)

GetUserInfo récupère les informations utilisateur d'un provider

func (*ExternalAuthService) LinkExternalAccount

func (s *ExternalAuthService) LinkExternalAccount(userID string, provider string, userInfo *model.ProviderUserInfo, tokenData *TokenExchangeResult) error

LinkExternalAccount lie un compte externe à un utilisateur existant

func (*ExternalAuthService) MigrateDiscordAccounts

func (s *ExternalAuthService) MigrateDiscordAccounts() error

MigrateDiscordAccounts migre les anciens comptes Discord vers le nouveau système ExternalAccount Cette fonction peut être appelée au démarrage de l'application ou via une route admin

func (*ExternalAuthService) RefreshAccessToken

func (s *ExternalAuthService) RefreshAccessToken(userID string, provider string) (string, error)

RefreshAccessToken rafraîchit le token d'accès si possible

func (*ExternalAuthService) UnlinkExternalAccount

func (s *ExternalAuthService) UnlinkExternalAccount(userID string, provider string) error

UnlinkExternalAccount supprime le lien avec un compte externe

func (*ExternalAuthService) ValidateOAuthState

func (s *ExternalAuthService) ValidateOAuthState(state string) (*model.OAuthState, error)

ValidateOAuthState valide et récupère un state OAuth

type JWTService

type JWTService struct {
	SecretKey       string
	AccessTokenExp  int
	RefreshTokenExp int
}

JWTService gère la création et la validation des tokens JWT

func NewJWTService

func NewJWTService(secretKey string, accessTokenExp, refreshTokenExp int) *JWTService

NewJWTService crée une nouvelle instance de JWTService

func (*JWTService) ExtractClaims

func (s *JWTService) ExtractClaims(tokenString string) (jwt.MapClaims, error)

ExtractClaims extrait les claims d'un token JWT

func (*JWTService) GenerateRefreshToken

func (s *JWTService) GenerateRefreshToken(userID string) (string, error)

GenerateRefreshToken crée un refresh token JWT

func (*JWTService) GenerateToken

func (s *JWTService) GenerateToken(user *model.User) (string, error)

GenerateToken crée un token JWT

func (*JWTService) ValidateToken

func (s *JWTService) ValidateToken(tokenString string) (*jwt.Token, error)

ValidateToken valide un token JWT

type ListUsersFilter

type ListUsersFilter struct {
	IsActive  *bool
	Search    string
	SortBy    string
	SortOrder string
}

ListUsersFilter représente les filtres pour la liste des utilisateurs

type ListUsersResponse

type ListUsersResponse struct {
	Users      []model.User `json:"users"`
	Total      int64        `json:"total"`
	Page       int          `json:"page"`
	Limit      int          `json:"limit"`
	TotalPages int          `json:"totalPages"`
}

ListUsersResponse représente la réponse paginée de la liste des utilisateurs

type OAuthService

type OAuthService struct {
	DB         *gorm.DB
	JWTService *JWTService
}

OAuthService gère les opérations OAuth2/OpenID Connect

func NewOAuthService

func NewOAuthService(db *gorm.DB, jwtService *JWTService) *OAuthService

NewOAuthService crée une nouvelle instance de OAuthService

func (*OAuthService) CreateAccessToken

func (s *OAuthService) CreateAccessToken(token, clientID string, userID string, scopes []string) (*model.OAuthAccessToken, error)

CreateAccessToken crée un token d'accès

func (*OAuthService) CreateAuthorizationCode

func (s *OAuthService) CreateAuthorizationCode(code, clientID string, userID string, redirectURI string, scopes []string) (*model.OAuthAuthorizationCode, error)

CreateAuthorizationCode crée un code d'autorisation

func (*OAuthService) CreateClient

func (s *OAuthService) CreateClient(client *model.OAuthClient) error

CreateClient crée un nouveau client OAuth2

func (*OAuthService) CreateConsent

func (s *OAuthService) CreateConsent(userID string, clientID string, scopes []string) (*model.OAuthConsent, error)

CreateConsent crée un consentement utilisateur

func (*OAuthService) CreateRefreshToken

func (s *OAuthService) CreateRefreshToken(token, clientID string, userID string) (*model.OAuthRefreshToken, error)

CreateRefreshToken crée un token de rafraîchissement

func (*OAuthService) DeleteAuthorizationCode

func (s *OAuthService) DeleteAuthorizationCode(code string) error

DeleteAuthorizationCode supprime un code d'autorisation

func (*OAuthService) GenerateAccessToken

func (s *OAuthService) GenerateAccessToken(user *model.User, client *model.OAuthClient, scopes []string) (string, error)

GenerateAccessToken génère un token d'accès OAuth2

func (*OAuthService) GenerateIDToken

func (s *OAuthService) GenerateIDToken(user *model.User, client *model.OAuthClient, scopes []string, nonce string) (string, error)

GenerateIDToken génère un ID token OpenID Connect

func (*OAuthService) GenerateRefreshToken

func (s *OAuthService) GenerateRefreshToken(userID string, clientID string) (string, error)

GenerateRefreshToken génère un token de rafraîchissement OAuth2

func (*OAuthService) GetAccessTokenByToken

func (s *OAuthService) GetAccessTokenByToken(token string) (*model.OAuthAccessToken, error)

GetAccessTokenByToken récupère un token d'accès par son token

func (*OAuthService) GetAuthorizationCodeByCode

func (s *OAuthService) GetAuthorizationCodeByCode(code string) (*model.OAuthAuthorizationCode, error)

GetAuthorizationCodeByCode récupère un code d'autorisation par son code

func (*OAuthService) GetClientByID

func (s *OAuthService) GetClientByID(clientID string) (*model.OAuthClient, error)

GetClientByID récupère un client par son ID

func (*OAuthService) GetConsentByUserAndClient

func (s *OAuthService) GetConsentByUserAndClient(userID string, clientID string) (*model.OAuthConsent, error)

GetConsentByUserAndClient récupère un consentement par utilisateur et client

func (*OAuthService) GetRefreshTokenByToken

func (s *OAuthService) GetRefreshTokenByToken(token string) (*model.OAuthRefreshToken, error)

GetRefreshTokenByToken récupère un token de rafraîchissement par son token

func (*OAuthService) RevokeAccessToken

func (s *OAuthService) RevokeAccessToken(token string) error

RevokeAccessToken révoque un token d'accès

func (*OAuthService) RevokeRefreshToken

func (s *OAuthService) RevokeRefreshToken(token string) error

RevokeRefreshToken révoque un token de rafraîchissement

func (*OAuthService) ValidateClient

func (s *OAuthService) ValidateClient(clientID, clientSecret string) (*model.OAuthClient, error)

ValidateClient valide un client OAuth2

func (*OAuthService) ValidateScopes

func (s *OAuthService) ValidateScopes(requestedScopes, allowedScopes []string) ([]string, error)

ValidateScopes valide les scopes demandés contre les scopes autorisés

func (*OAuthService) ValidateToken

func (s *OAuthService) ValidateToken(tokenString string) (*jwt.Token, error)

ValidateToken valide un token OAuth2

type ServiceKeyService

type ServiceKeyService struct {
	DB *gorm.DB
}

ServiceKeyService handles service key operations

func NewServiceKeyService

func NewServiceKeyService(db *gorm.DB) *ServiceKeyService

NewServiceKeyService creates a new ServiceKeyService

func (*ServiceKeyService) CreateServiceKey

func (s *ServiceKeyService) CreateServiceKey(name, description string, expiresAt *time.Time, createdBy uint) (*model.ServiceKey, error)

CreateServiceKey creates a new service key

func (*ServiceKeyService) DeleteServiceKey

func (s *ServiceKeyService) DeleteServiceKey(id uint) error

DeleteServiceKey deletes a service key

func (*ServiceKeyService) GetServiceKey

func (s *ServiceKeyService) GetServiceKey(id uint) (*model.ServiceKey, error)

GetServiceKey retrieves a service key by ID

func (*ServiceKeyService) GetServiceKeyByKey

func (s *ServiceKeyService) GetServiceKeyByKey(key string) (*model.ServiceKey, error)

GetServiceKeyByKey retrieves a service key by its key

func (*ServiceKeyService) ListServiceKeys

func (s *ServiceKeyService) ListServiceKeys(limit, offset int) ([]model.ServiceKey, int64, error)

ListServiceKeys lists all service keys

func (*ServiceKeyService) ListServiceKeysByUser

func (s *ServiceKeyService) ListServiceKeysByUser(userID uint, page, limit int) ([]model.ServiceKey, int64, error)

ListServiceKeysByUser lists all service keys created by a specific user with pagination

func (*ServiceKeyService) LogServiceKeyUsage

func (s *ServiceKeyService) LogServiceKeyUsage(serviceKeyID uint, endpoint, method, ipAddress, userAgent string, statusCode int) error

LogServiceKeyUsage logs the usage of a service key

func (*ServiceKeyService) UpdateServiceKey

func (s *ServiceKeyService) UpdateServiceKey(id uint, name, description string, isActive bool, expiresAt *time.Time, updatedBy uint) (*model.ServiceKey, error)

UpdateServiceKey updates a service key

func (*ServiceKeyService) ValidateServiceKey

func (s *ServiceKeyService) ValidateServiceKey(key string) (bool, error)

ValidateServiceKey validates a service key

type TOTPService

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

TOTPService manages TOTP-related operations

func NewTOTPService

func NewTOTPService(db *gorm.DB) *TOTPService

NewTOTPService creates a new TOTPService instance

func (*TOTPService) DisableTOTP

func (s *TOTPService) DisableTOTP(userID string) error

DisableTOTP disables TOTP for a user

func (*TOTPService) EnableTOTP

func (s *TOTPService) EnableTOTP(userID string, secret string) error

EnableTOTP enables TOTP for a user

func (*TOTPService) GenerateQRCode

func (s *TOTPService) GenerateQRCode(url string) (barcode.Barcode, error)

GenerateQRCode generates a QR code for the provided URL

func (*TOTPService) GenerateTOTPSecret

func (s *TOTPService) GenerateTOTPSecret(userID uint) (string, string, error)

GenerateTOTPSecret generates a new TOTP secret and otpauth URL

func (*TOTPService) GetTOTPStatus

func (s *TOTPService) GetTOTPStatus(userID string) (bool, error)

GetTOTPStatus returns the TOTP enabled status for a user

func (*TOTPService) VerifyTOTPCode

func (s *TOTPService) VerifyTOTPCode(code, secret string) (bool, error)

VerifyTOTPCode verifies a TOTP code against a secret

func (*TOTPService) VerifyTOTPLogin

func (s *TOTPService) VerifyTOTPLogin(email, password, totpCode string) (*model.User, error)

VerifyTOTPLogin verifies a TOTP during login

type TokenExchangeResult

type TokenExchangeResult struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
}

TokenExchangeResult représente le résultat d'un échange de code

type UserService

type UserService struct {
	DB *gorm.DB
}

UserService gère les opérations liées aux utilisateurs

func NewUserService

func NewUserService(db *gorm.DB) *UserService

NewUserService crée une nouvelle instance de UserService

func (*UserService) AuthenticateUser

func (s *UserService) AuthenticateUser(email, password string) (*model.User, error)

AuthenticateUser authentifie un utilisateur

func (*UserService) CheckEmailExists

func (s *UserService) CheckEmailExists(email string) bool

CheckEmailExists vérifie si un email existe déjà

func (*UserService) CreateUser

func (s *UserService) CreateUser(user *model.User, password string) error

CreateUser crée un nouvel utilisateur avec validation

func (*UserService) DeleteUser

func (s *UserService) DeleteUser(id string) error

DeleteUser supprime un utilisateur

func (*UserService) GetUserByEmail

func (s *UserService) GetUserByEmail(email string) (*model.User, error)

GetUserByEmail récupère un utilisateur par son email

func (*UserService) GetUserByID

func (s *UserService) GetUserByID(id string) (*model.User, error)

GetUserByID récupère un utilisateur par son ID

func (*UserService) ListUsers

func (s *UserService) ListUsers(page, limit int, filter ListUsersFilter) (*ListUsersResponse, error)

ListUsers récupère la liste des utilisateurs avec pagination et filtres

func (*UserService) UpdateUser

func (s *UserService) UpdateUser(user *model.User, newPassword *string) error

UpdateUser met à jour un utilisateur

func (*UserService) UserToResponse

func (s *UserService) UserToResponse(user *model.User) map[string]interface{}

UserToResponse convertit un modèle User en une réponse appropriée

Jump to

Keyboard shortcuts

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