52 lines
2.2 KiB
Go
52 lines
2.2 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
UserName string `json:"username" gorm:"type:varchar(255)"`
|
|
Email string `gorm:"uniqueIndex;not null;type:varchar(255)" json:"email"`
|
|
Password string `json:"-" gorm:"type:varchar(255)"` // Password shouldn't be returned in JSON
|
|
EmailVerified *bool `gorm:"default:false" json:"email_verified"` // default false for email/password registration
|
|
EmailVerifyToken string `gorm:"index;type:varchar(255)" json:"-"`
|
|
EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
|
|
IsAdmin *bool `gorm:"default:false" json:"is_admin"`
|
|
SocialAccounts []SocialAccount `gorm:"foreignKey:UserID" json:"social_accounts,omitempty"`
|
|
Profile []Profile `gorm:"foreignKey:UserID" json:"profiles,omitempty"`
|
|
}
|
|
|
|
// Email Veriyf i False Döndürüyor
|
|
func (u *User) IsEmailVerified() bool {
|
|
if u.EmailVerified == nil {
|
|
return false
|
|
}
|
|
return *u.EmailVerified
|
|
}
|
|
|
|
// SocialAccount model structure
|
|
type SocialAccount struct {
|
|
gorm.Model
|
|
UserID uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
|
|
Provider string `gorm:"not null" json:"provider"` // google, github
|
|
ProviderID string `gorm:"not null" json:"provider_id"`
|
|
Email string `json:"email" gorm:"type:varchar(255)"`
|
|
Name string `json:"name,omitempty" gorm:"type:varchar(255)"` // Full name from provider
|
|
AvatarURL string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider
|
|
|
|
}
|
|
type Profile struct {
|
|
gorm.Model
|
|
UserID uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
|
|
AvatarURL string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider
|
|
FirstName string `json:"first_name" gorm:"type:varchar(255)"` // Full name from provider
|
|
LastName string `json:"last_name" gorm:"type:varchar(255)"` // Full name from provider
|
|
|
|
}
|