models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const HighValueThreshold int64 = 1000000 // ₹10,000.00

HighValueThreshold is the amount (in paisa) above which transfers require verification.

Variables

This section is empty.

Functions

func IsValidOperationType

func IsValidOperationType(op OperationType) bool

IsValidOperationType checks if the operation type is valid.

func ValidOperationTypes

func ValidOperationTypes() map[OperationType]bool

ValidOperationTypes returns the list of valid operation types.

Types

type AccountType

type AccountType string

AccountType represents the type of user account.

const (
	AccountTypeUser       AccountType = "user"        // Regular user account
	AccountTypeUserAdmin  AccountType = "user_admin"  // User-Admin for verification (paired with regular user)
	AccountTypeAdmin      AccountType = "admin"       // Platform administrator
	AccountTypeSuperAdmin AccountType = "super_admin" // Super administrator
)

type Address

type Address struct {
	Street  string `json:"street"`
	City    string `json:"city"`
	State   string `json:"state"`
	PIN     string `json:"pin"`     // 6-digit Indian PIN code
	Country string `json:"country"` // Default: "IN"
}

Address represents an Indian address.

type AdminPortalInfo

type AdminPortalInfo struct {
	Available   bool   `json:"available"`   // Whether User-Admin portal is available
	Description string `json:"description"` // Explanation of what the portal is for
}

AdminPortalInfo contains information about the User-Admin portal for verification.

type ChangePasswordRequest

type ChangePasswordRequest struct {
	CurrentPassword string `json:"current_password" validate:"required"`
	NewPassword     string `json:"new_password" validate:"required,min=8,max=100"`
}

ChangePasswordRequest represents the request to change user password.

type CreateUserRequest

type CreateUserRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Phone    string `json:"phone" validate:"required,indian_phone"`
	FullName string `json:"full_name" validate:"required,min=2,max=100"`
	Password string `json:"password" validate:"required,min=8,max=100"`
}

CreateUserRequest represents the request to create a new user (registration).

type CreateVerificationRequest

type CreateVerificationRequest struct {
	OperationType OperationType          `json:"operation_type" validate:"required"`
	Metadata      map[string]interface{} `json:"metadata,omitempty"`
}

CreateVerificationRequest represents the request to create a verification.

type KYCInfo

type KYCInfo struct {
	UserID          string            `json:"user_id" db:"user_id"`
	Status          KYCStatus         `json:"status" db:"status"`
	PAN             string            `json:"pan" db:"pan"`                     // Permanent Account Number
	Aadhaar         string            `json:"-" db:"aadhaar"`                   // Never expose in API (PII)
	DateOfBirth     string            `json:"date_of_birth" db:"date_of_birth"` // YYYY-MM-DD
	Address         Address           `json:"address" db:"-"`                   // Stored as JSONB
	VerifiedAt      *models.Timestamp `json:"verified_at,omitempty" db:"verified_at"`
	RejectedAt      *models.Timestamp `json:"rejected_at,omitempty" db:"rejected_at"`
	RejectionReason string            `json:"rejection_reason,omitempty" db:"rejection_reason"`
	CreatedAt       models.Timestamp  `json:"created_at" db:"created_at"`
	UpdatedAt       models.Timestamp  `json:"updated_at" db:"updated_at"`
}

KYCInfo contains India-specific KYC information.

func (*KYCInfo) IsKYCVerified

func (k *KYCInfo) IsKYCVerified() bool

IsKYCVerified returns true if KYC is verified.

type KYCStatus

type KYCStatus string

KYCStatus represents the KYC verification status.

const (
	KYCStatusPending  KYCStatus = "pending"  // KYC documents submitted
	KYCStatusVerified KYCStatus = "verified" // KYC approved
	KYCStatusRejected KYCStatus = "rejected" // KYC rejected
	KYCStatusExpired  KYCStatus = "expired"  // KYC documents expired
)

type LoginRequest

type LoginRequest struct {
	Identifier string     `json:"identifier" validate:"required"` // Email or phone number
	Password   string     `json:"password" validate:"required"`
	Portal     PortalType `json:"portal,omitempty"` // Portal context: "user" or "admin" (defaults to "user")
}

LoginRequest represents the login credentials. Identifier can be either email or phone number.

type LoginResponse

type LoginResponse struct {
	Token        string           `json:"token"`
	ExpiresAt    int64            `json:"expires_at"`
	User         *User            `json:"user"`
	AccountType  AccountType      `json:"account_type"`             // Account type for easy frontend handling
	PairedUserID string           `json:"paired_user_id,omitempty"` // For User-Admin: the regular user ID
	AdminPortal  *AdminPortalInfo `json:"admin_portal,omitempty"`   // For regular users: admin portal info
}

LoginResponse contains the authentication token.

type OperationType

type OperationType string

OperationType represents the type of operation requiring verification.

const (
	OpPasswordChange    OperationType = "password_change"
	OpEmailChange       OperationType = "email_change"
	OpPhoneChange       OperationType = "phone_change"
	OpHighValueTransfer OperationType = "high_value_transfer"
	OpBeneficiaryAdd    OperationType = "beneficiary_add"
	Op2FAEnable         OperationType = "2fa_enable"
	Op2FADisable        OperationType = "2fa_disable"
)

type PortalType

type PortalType string

PortalType represents the login portal context.

const (
	PortalTypeUser  PortalType = "user"  // User app (nivomoney.com)
	PortalTypeAdmin PortalType = "admin" // Admin app (admin.nivomoney.com)
)

type Session

type Session struct {
	ID        string           `json:"id" db:"id"`
	UserID    string           `json:"user_id" db:"user_id"`
	Token     string           `json:"token" db:"token_hash"` // JWT token hash
	IPAddress string           `json:"ip_address" db:"ip_address"`
	UserAgent string           `json:"user_agent" db:"user_agent"`
	ExpiresAt models.Timestamp `json:"expires_at" db:"expires_at"`
	CreatedAt models.Timestamp `json:"created_at" db:"created_at"`
}

Session represents an active user session.

type UpdateKYCRequest

type UpdateKYCRequest struct {
	PAN         string  `json:"pan" validate:"required,pan"`
	Aadhaar     string  `json:"aadhaar" validate:"required,aadhaar"`
	DateOfBirth string  `json:"date_of_birth" validate:"required"` // Format: YYYY-MM-DD
	Address     Address `json:"address" validate:"required"`
}

UpdateKYCRequest represents KYC document submission.

type UpdateProfileRequest

type UpdateProfileRequest struct {
	FullName string `json:"full_name" validate:"required,min=2,max=100"`
	Email    string `json:"email" validate:"required,email"`
	Phone    string `json:"phone" validate:"required,indian_phone"`
}

UpdateProfileRequest represents the request to update user profile.

type User

type User struct {
	ID          string           `json:"id" db:"id"`
	Email       string           `json:"email" db:"email"`
	Phone       string           `json:"phone" db:"phone"` // Indian phone with +91
	FullName    string           `json:"full_name" db:"full_name"`
	Status      UserStatus       `json:"status" db:"status"`
	AccountType AccountType      `json:"account_type" db:"account_type"` // user, user_admin, admin, super_admin
	CreatedAt   models.Timestamp `json:"created_at" db:"created_at"`
	UpdatedAt   models.Timestamp `json:"updated_at" db:"updated_at"`

	// Password (hashed, never exposed in JSON)
	PasswordHash string `json:"-" db:"password_hash"`

	// Suspension tracking (admin actions)
	SuspendedAt      *models.Timestamp `json:"suspended_at,omitempty" db:"suspended_at"`
	SuspensionReason *string           `json:"suspension_reason,omitempty" db:"suspension_reason"`
	SuspendedBy      *string           `json:"suspended_by,omitempty" db:"suspended_by"` // Admin user ID

	// KYC Information (India-specific)
	KYC KYCInfo `json:"kyc" db:"-"` // Embedded, stored separately
}

User represents a Nivo user with India-specific identity fields.

func (*User) IsActive

func (u *User) IsActive() bool

IsActive returns true if the user account is active.

func (*User) IsSuspended

func (u *User) IsSuspended() bool

IsSuspended returns true if the user is suspended.

func (*User) Sanitize

func (u *User) Sanitize()

Sanitize removes sensitive information from User before returning in API.

type UserStatus

type UserStatus string

UserStatus represents the current state of a user account.

const (
	UserStatusPending   UserStatus = "pending"   // Awaiting KYC verification
	UserStatusActive    UserStatus = "active"    // KYC verified, account active
	UserStatusSuspended UserStatus = "suspended" // Temporarily disabled
	UserStatusClosed    UserStatus = "closed"    // Permanently closed
)

type VerificationClaims

type VerificationClaims struct {
	VerificationID string           `json:"verification_id"`
	UserID         string           `json:"user_id"`
	OperationType  OperationType    `json:"operation_type"`
	Metadata       VerificationMeta `json:"metadata,omitempty"`
	jwt.RegisteredClaims
}

VerificationClaims contains the JWT claims for a verification token.

type VerificationMeta

type VerificationMeta map[string]interface{}

VerificationMeta stores operation-specific context data.

func (*VerificationMeta) Scan

func (m *VerificationMeta) Scan(value interface{}) error

Scan implements sql.Scanner for VerificationMeta.

func (VerificationMeta) Value

func (m VerificationMeta) Value() (driver.Value, error)

Value implements driver.Valuer for VerificationMeta.

type VerificationRequest

type VerificationRequest struct {
	ID            string                  `json:"id" db:"id"`
	UserID        string                  `json:"user_id" db:"user_id"`
	OperationType OperationType           `json:"operation_type" db:"operation_type"`
	OTPCode       string                  `json:"otp_code,omitempty" db:"otp_code"` // Only visible to User-Admin
	Status        VerificationStatus      `json:"status" db:"status"`
	Metadata      VerificationMeta        `json:"metadata,omitempty" db:"metadata"`
	ExpiresAt     sharedModels.Timestamp  `json:"expires_at" db:"expires_at"`
	CreatedAt     sharedModels.Timestamp  `json:"created_at" db:"created_at"`
	VerifiedAt    *sharedModels.Timestamp `json:"verified_at,omitempty" db:"verified_at"`
	AttemptCount  int                     `json:"attempt_count" db:"attempt_count"`
	LastAttemptAt *sharedModels.Timestamp `json:"last_attempt_at,omitempty" db:"last_attempt_at"`
}

VerificationRequest represents a verification request with OTP code.

func (*VerificationRequest) IsExpired

func (v *VerificationRequest) IsExpired() bool

IsExpired checks if the verification request has expired.

func (*VerificationRequest) IsPending

func (v *VerificationRequest) IsPending() bool

IsPending checks if the verification is still pending.

func (*VerificationRequest) SanitizeForUser

func (v *VerificationRequest) SanitizeForUser() *VerificationRequest

SanitizeForUser removes OTP code (for regular user view).

type VerificationStatus

type VerificationStatus string

VerificationStatus represents the status of a verification request.

const (
	VerificationStatusPending   VerificationStatus = "pending"
	VerificationStatusVerified  VerificationStatus = "verified"
	VerificationStatusExpired   VerificationStatus = "expired"
	VerificationStatusCancelled VerificationStatus = "cancelled"
)

type VerificationToken

type VerificationToken struct {
	Token         string           `json:"token"`
	OperationType OperationType    `json:"operation_type"`
	Metadata      VerificationMeta `json:"metadata,omitempty"`
	ExpiresAt     time.Time        `json:"expires_at"`
}

VerificationToken represents a short-lived token for completing verified operations.

type VerifyOTPRequest

type VerifyOTPRequest struct {
	OTP string `json:"otp" validate:"required,len=6,numeric"`
}

VerifyOTPRequest represents the request to verify an OTP.

Jump to

Keyboard shortcuts

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