Passport/pkg/models/accounts.go

59 lines
1.9 KiB
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package models
2024-01-07 07:52:23 +00:00
import (
2024-01-28 16:32:39 +00:00
"github.com/samber/lo"
2024-01-31 16:14:25 +00:00
"github.com/spf13/viper"
"path/filepath"
2024-01-07 07:52:23 +00:00
"time"
)
2024-01-06 17:56:32 +00:00
type Account struct {
BaseModel
2024-02-07 15:15:16 +00:00
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
2024-02-28 15:30:29 +00:00
Description string `json:"description"`
2024-02-07 15:15:16 +00:00
Avatar string `json:"avatar"`
Profile AccountProfile `json:"profile"`
Sessions []AuthSession `json:"sessions"`
Challenges []AuthChallenge `json:"challenges"`
Factors []AuthFactor `json:"factors"`
Contacts []AccountContact `json:"contacts"`
Events []ActionEvent `json:"events"`
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
ThirdClients []ThirdClient `json:"clients"`
Notifications []Notification `json:"notifications" gorm:"foreignKey:RecipientID"`
NotifySubscribers []NotificationSubscriber `json:"notify_subscribers"`
ConfirmedAt *time.Time `json:"confirmed_at"`
PowerLevel int `json:"power_level"`
2024-01-06 17:56:32 +00:00
}
2024-01-28 16:32:39 +00:00
func (v Account) GetPrimaryEmail() AccountContact {
val, _ := lo.Find(v.Contacts, func(item AccountContact) bool {
return item.Type == EmailAccountContact && item.IsPrimary
})
return val
}
2024-01-31 16:14:25 +00:00
func (v Account) GetAvatarPath() string {
basepath := viper.GetString("content")
return filepath.Join(basepath, v.Avatar)
}
2024-01-06 17:56:32 +00:00
type AccountContactType = int8
const (
EmailAccountContact = AccountContactType(iota)
)
type AccountContact struct {
BaseModel
Type int8 `json:"type"`
Content string `json:"content" gorm:"uniqueIndex"`
IsPublic bool `json:"is_public"`
IsPrimary bool `json:"is_primary"`
VerifiedAt *time.Time `json:"verified_at"`
AccountID uint `json:"account_id"`
}