mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-22 23:42:16 +00:00
This pull request introduces a new set of domain models and repositories for managing users within the new v3 structure. The goal is to establish a clean, robust, and extensible foundation for user management. ### Summary This PR accomplishes the following: - **Polymorphic User Model**: Introduces a `User` model in user.go that can represent either a `Human` or a `Machine` user. This provides a unified way to handle different user types while allowing for specific attributes and logic for each. - **Repository Pattern**: Implements the repository pattern for accessing and manipulating user data. This decouples the business logic from the data storage implementation. The main repository interfaces (`UserRepository`, `HumanUserRepository`, `MachineUserRepository`) are now defined in `backend/v3/domain/user_repository.go`. - **Comprehensive User Models**: The user.go file now also defines the domain models for associated user data, including `UserMetadata`, `IdentityProviderLink`, `Passkey`, `PersonalAccessToken`, and `MachineKey`. - **Generic Verification and Check System**: Introduces verification.go and check.go to provide a standardized way of handling various verification flows (e.g., email verification, OTP checks). - **Generated Code**: Adds new generated files for enums (`humangender_enumer.go`, `machinekeytype_enumer.go`, `passkeytype_enumer.go`, `personalaccesstokentype_enumer.go`, `userstate_enumer.go`, `usertype_enumer.go`) and mocks for the new repositories. - **Session Domain Refactoring**: Updates the session domain (`backend/v3/domain/session*.go`) to align with the new user model structure. This foundational work paves the way for migrating user management logic to the new `v3` backend, with a more maintainable and testable architecture. part of #10224 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Marco A. <[email protected]>
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type Verification struct {
|
|
Value *string `db:"value"`
|
|
Code []byte `db:"code"`
|
|
ExpiresAt *time.Time `db:"expires_at"`
|
|
FailedAttempts uint8 `db:"failed_attempts"`
|
|
VerifiedAt time.Time `db:"verified_at"`
|
|
}
|
|
|
|
type VerificationType interface {
|
|
isVerificationType()
|
|
}
|
|
|
|
// VerificationTypeInit indicates that an object which needs verification is created.
|
|
type VerificationTypeInit struct {
|
|
// CreatedAt is the time when the verification was created.
|
|
// If zero, the current time will be used.
|
|
CreatedAt time.Time
|
|
// Expiry is the duration after which the verification expires.
|
|
Expiry *time.Duration
|
|
// Code is the code to be used for verification.
|
|
Code []byte
|
|
// Value is the value to be set after successful verification.
|
|
Value *string
|
|
}
|
|
|
|
// isVerificationType implements [VerificationType].
|
|
func (v *VerificationTypeInit) isVerificationType() {}
|
|
|
|
var _ VerificationType = (*VerificationTypeInit)(nil)
|
|
|
|
// VerificationTypeVerified indicates that the verification was successful.
|
|
// If VerifiedAt is zero, the current time will be used.
|
|
// If the Value of the verification is present, it is used as the new value to be set.
|
|
type VerificationTypeVerified struct {
|
|
VerifiedAt time.Time
|
|
}
|
|
|
|
// isVerificationType implements [VerificationType].
|
|
func (v *VerificationTypeVerified) isVerificationType() {}
|
|
|
|
var _ VerificationType = (*VerificationTypeVerified)(nil)
|
|
|
|
// VerificationTypeUpdate updates an existing verification.
|
|
// Non-nil fields get updated.
|
|
type VerificationTypeUpdate struct {
|
|
Code []byte
|
|
Value *string
|
|
Expiry *time.Duration
|
|
}
|
|
|
|
// isVerificationType implements [VerificationType].
|
|
func (v *VerificationTypeUpdate) isVerificationType() {}
|
|
|
|
var _ VerificationType = (*VerificationTypeUpdate)(nil)
|
|
|
|
// VerificationTypeSkipped indicates that the verification was skipped.
|
|
// If Value is present, it is used as the new value to be set.
|
|
type VerificationTypeSkipped struct {
|
|
VerifiedAt time.Time
|
|
Value *string
|
|
}
|
|
|
|
// isVerificationType implements [VerificationType].
|
|
func (v *VerificationTypeSkipped) isVerificationType() {}
|
|
|
|
var _ VerificationType = (*VerificationTypeSkipped)(nil)
|
|
|
|
type VerificationTypeFailed struct {
|
|
FailedAt time.Time
|
|
}
|
|
|
|
// isVerificationType implements [VerificationType].
|
|
func (v *VerificationTypeFailed) isVerificationType() {}
|
|
|
|
var _ VerificationType = (*VerificationTypeFailed)(nil)
|