user auth register
This commit is contained in:
@@ -8,17 +8,20 @@ import (
|
||||
)
|
||||
|
||||
type Customer struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
OrganizationID uuid.UUID `gorm:"type:uuid;not null;index" json:"organization_id" validate:"required"`
|
||||
Name string `gorm:"not null;size:255" json:"name" validate:"required"`
|
||||
Email *string `gorm:"size:255;uniqueIndex" json:"email,omitempty"`
|
||||
Phone *string `gorm:"size:20" json:"phone,omitempty"`
|
||||
Address *string `gorm:"size:500" json:"address,omitempty"`
|
||||
IsDefault bool `gorm:"default:false" json:"is_default"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
Metadata Metadata `gorm:"type:jsonb;default:'{}'" json:"metadata"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
OrganizationID uuid.UUID `gorm:"type:uuid;not null;index" json:"organization_id" validate:"required"`
|
||||
Name string `gorm:"not null;size:255" json:"name" validate:"required"`
|
||||
Email *string `gorm:"size:255;uniqueIndex" json:"email,omitempty"`
|
||||
Phone *string `gorm:"size:20" json:"phone,omitempty"`
|
||||
PhoneNumber *string `gorm:"size:20;uniqueIndex" json:"phone_number,omitempty"`
|
||||
Address *string `gorm:"size:500" json:"address,omitempty"`
|
||||
BirthDate *time.Time `gorm:"type:date" json:"birth_date,omitempty"`
|
||||
PasswordHash *string `gorm:"size:255" json:"-"`
|
||||
IsDefault bool `gorm:"default:false" json:"is_default"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
Metadata Metadata `gorm:"type:jsonb;default:'{}'" json:"metadata"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
|
||||
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
||||
Orders []Order `gorm:"foreignKey:CustomerID" json:"orders,omitempty"`
|
||||
|
||||
@@ -34,6 +34,7 @@ func GetAllEntities() []interface{} {
|
||||
&Reward{},
|
||||
&Campaign{},
|
||||
&CampaignRule{},
|
||||
&OtpSession{},
|
||||
// Analytics entities are not database tables, they are query results
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type OtpSession struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
Token string `gorm:"type:varchar(255);uniqueIndex;not null" json:"token"`
|
||||
Code string `gorm:"type:varchar(10);not null" json:"code"`
|
||||
PhoneNumber string `gorm:"type:varchar(20);not null;index" json:"phone_number"`
|
||||
Purpose string `gorm:"type:varchar(50);not null;index" json:"purpose"`
|
||||
ExpiresAt time.Time `gorm:"not null;index" json:"expires_at"`
|
||||
IsUsed bool `gorm:"default:false;index" json:"is_used"`
|
||||
AttemptsCount int `gorm:"default:0" json:"attempts_count"`
|
||||
MaxAttempts int `gorm:"default:3" json:"max_attempts"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (o *OtpSession) BeforeCreate(tx *gorm.DB) error {
|
||||
if o.ID == uuid.Nil {
|
||||
o.ID = uuid.New()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (OtpSession) TableName() string {
|
||||
return "otp_sessions"
|
||||
}
|
||||
|
||||
func (o *OtpSession) IsExpired() bool {
|
||||
return time.Now().After(o.ExpiresAt)
|
||||
}
|
||||
|
||||
func (o *OtpSession) IsMaxAttemptsReached() bool {
|
||||
return o.AttemptsCount >= o.MaxAttempts
|
||||
}
|
||||
|
||||
func (o *OtpSession) CanBeUsed() bool {
|
||||
return !o.IsUsed && !o.IsExpired() && !o.IsMaxAttemptsReached()
|
||||
}
|
||||
|
||||
func (o *OtpSession) IncrementAttempts() {
|
||||
o.AttemptsCount++
|
||||
}
|
||||
|
||||
func (o *OtpSession) MarkAsUsed() {
|
||||
o.IsUsed = true
|
||||
}
|
||||
Reference in New Issue
Block a user