mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-08 15:15:12 +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]>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type Check struct {
|
|
Code []byte `db:"code"`
|
|
ExpiresAt *time.Time `db:"expires_at"`
|
|
FailedAttempts uint8 `db:"failed_attempts"`
|
|
}
|
|
|
|
type CheckType interface {
|
|
isCheckType()
|
|
}
|
|
|
|
type PasswordCheckType interface {
|
|
isPasswordCheckType()
|
|
}
|
|
|
|
// CheckTypeInit initializes a new check.
|
|
type CheckTypeInit struct {
|
|
// CreatedAt is the time when the check was created.
|
|
// If zero, the current time will be used.
|
|
CreatedAt time.Time
|
|
// Expiry is the duration after which the check expires.
|
|
Expiry *time.Duration
|
|
// Code to be used for the check.
|
|
Code []byte
|
|
}
|
|
|
|
// isCheckType implements [CheckType].
|
|
func (v *CheckTypeInit) isCheckType() {}
|
|
|
|
var _ CheckType = (*CheckTypeInit)(nil)
|
|
|
|
// CheckTypeFailed indicates that the check failed.
|
|
// It is used to increment the failed attempts counter.
|
|
type CheckTypeFailed struct {
|
|
FailedAt time.Time
|
|
}
|
|
|
|
// isCheckType implements [CheckType].
|
|
func (v *CheckTypeFailed) isCheckType() {}
|
|
|
|
// isPasswordCheckType implements [PasswordCheckType].
|
|
func (v *CheckTypeFailed) isPasswordCheckType() {}
|
|
|
|
var (
|
|
_ CheckType = (*CheckTypeFailed)(nil)
|
|
_ PasswordCheckType = (*CheckTypeFailed)(nil)
|
|
)
|
|
|
|
// CheckTypeSucceeded indicates that the check succeeded.
|
|
// It is used to reset the failed attempts counter.
|
|
type CheckTypeSucceeded struct {
|
|
SucceededAt time.Time
|
|
}
|
|
|
|
// isCheckType implements [CheckType].
|
|
func (v *CheckTypeSucceeded) isCheckType() {}
|
|
|
|
// isPasswordCheckType implements [PasswordCheckType].
|
|
func (v *CheckTypeSucceeded) isPasswordCheckType() {}
|
|
|
|
var (
|
|
_ CheckType = (*CheckTypeSucceeded)(nil)
|
|
_ PasswordCheckType = (*CheckTypeSucceeded)(nil)
|
|
)
|