2022-09-28 09:01:17 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
GenderMale = "male"
|
|
|
|
GenderFemale = "female"
|
|
|
|
GenderOther = "other"
|
|
|
|
GenderUnknown = ""
|
|
|
|
)
|
|
|
|
|
|
|
|
// UserDetails represents user profile information.
|
|
|
|
type UserDetails struct {
|
2022-10-17 19:07:38 +02:00
|
|
|
UserUID string `gorm:"type:VARBINARY(42);primary_key;auto_increment:false;" json:"-" yaml:"-"`
|
|
|
|
SubjUID string `gorm:"type:VARBINARY(42);index;" json:"SubjUID,omitempty" yaml:"SubjUID,omitempty"`
|
|
|
|
SubjSrc string `gorm:"type:VARBINARY(8);default:'';" json:"-" yaml:"SubjSrc,omitempty"`
|
|
|
|
PlaceID string `gorm:"type:VARBINARY(42);index;default:'zz'" json:"-" yaml:"-"`
|
|
|
|
PlaceSrc string `gorm:"type:VARBINARY(8);" json:"-" yaml:"PlaceSrc,omitempty"`
|
|
|
|
CellID string `gorm:"type:VARBINARY(42);index;default:'zz'" json:"-" yaml:"CellID,omitempty"`
|
2022-10-19 05:09:09 +02:00
|
|
|
BirthYear int `json:"BirthYear" yaml:"BirthYear,omitempty"`
|
|
|
|
BirthMonth int `json:"BirthMonth" yaml:"BirthMonth,omitempty"`
|
|
|
|
BirthDay int `json:"BirthDay" yaml:"BirthDay,omitempty"`
|
|
|
|
NameTitle string `gorm:"size:32;" json:"NameTitle" yaml:"NameTitle,omitempty"`
|
2022-10-17 19:07:38 +02:00
|
|
|
GivenName string `gorm:"size:64;" json:"GivenName" yaml:"GivenName,omitempty"`
|
|
|
|
MiddleName string `gorm:"size:64;" json:"MiddleName" yaml:"MiddleName,omitempty"`
|
|
|
|
FamilyName string `gorm:"size:64;" json:"FamilyName" yaml:"FamilyName,omitempty"`
|
|
|
|
NameSuffix string `gorm:"size:32;" json:"NameSuffix" yaml:"NameSuffix,omitempty"`
|
|
|
|
NickName string `gorm:"size:64;" json:"NickName" yaml:"NickName,omitempty"`
|
2022-10-19 05:09:09 +02:00
|
|
|
NameSrc string `gorm:"type:VARBINARY(8);" json:"NameSrc" yaml:"NameSrc,omitempty"`
|
2022-10-17 19:07:38 +02:00
|
|
|
UserGender string `gorm:"size:16;" json:"Gender" yaml:"Gender,omitempty"`
|
2022-10-19 05:09:09 +02:00
|
|
|
UserAbout string `gorm:"size:512;" json:"About" yaml:"About,omitempty"`
|
2022-10-17 19:07:38 +02:00
|
|
|
UserBio string `gorm:"size:512;" json:"Bio" yaml:"Bio,omitempty"`
|
|
|
|
UserLocation string `gorm:"size:512;" json:"Location" yaml:"Location,omitempty"`
|
|
|
|
UserCountry string `gorm:"type:VARBINARY(2);" json:"Country" yaml:"Country,omitempty"`
|
|
|
|
UserPhone string `gorm:"size:32;" json:"Phone" yaml:"Phone,omitempty"`
|
|
|
|
SiteURL string `gorm:"type:VARBINARY(512);column:site_url" json:"SiteURL" yaml:"SiteURL,omitempty"`
|
|
|
|
ProfileURL string `gorm:"type:VARBINARY(512);column:profile_url" json:"ProfileURL" yaml:"ProfileURL,omitempty"`
|
|
|
|
FeedURL string `gorm:"type:VARBINARY(512);column:feed_url" json:"FeedURL,omitempty" yaml:"FeedURL,omitempty"`
|
|
|
|
AvatarURL string `gorm:"type:VARBINARY(512);column:avatar_url" json:"AvatarURL,omitempty" yaml:"AvatarURL,omitempty"`
|
|
|
|
OrgTitle string `gorm:"size:64;" json:"OrgTitle" yaml:"OrgTitle,omitempty"`
|
2022-10-19 05:09:09 +02:00
|
|
|
OrgName string `gorm:"size:128;" json:"OrgName" yaml:"OrgName,omitempty"`
|
2022-10-17 19:07:38 +02:00
|
|
|
OrgEmail string `gorm:"size:255;index;" json:"OrgEmail" yaml:"OrgEmail,omitempty"`
|
|
|
|
OrgPhone string `gorm:"size:32;" json:"OrgPhone" yaml:"OrgPhone,omitempty"`
|
|
|
|
OrgURL string `gorm:"type:VARBINARY(512);column:org_url" json:"OrgURL" yaml:"OrgURL,omitempty"`
|
2022-10-19 05:09:09 +02:00
|
|
|
IdURL string `gorm:"type:VARBINARY(512);column:id_url;" json:"IdURL,omitempty" yaml:"IdURL,omitempty"`
|
2022-10-17 19:07:38 +02:00
|
|
|
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
|
|
|
|
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TableName returns the entity table name.
|
|
|
|
func (UserDetails) TableName() string {
|
2022-10-02 22:09:02 +02:00
|
|
|
return "auth_users_details"
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewUserDetails creates new user details.
|
|
|
|
func NewUserDetails(uid string) *UserDetails {
|
|
|
|
return &UserDetails{UserUID: uid}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateUserDetails creates new user details or returns nil on error.
|
|
|
|
func CreateUserDetails(user *User) error {
|
|
|
|
if user == nil {
|
|
|
|
return fmt.Errorf("user is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.UID() == "" {
|
|
|
|
return fmt.Errorf("empty user uid")
|
|
|
|
}
|
|
|
|
|
|
|
|
user.UserDetails = NewUserDetails(user.UID())
|
|
|
|
|
|
|
|
if err := Db().Where("user_uid = ?", user.UID()).First(user.UserDetails).Error; err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return user.UserDetails.Create()
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasID tests if the entity has a valid uid.
|
|
|
|
func (m *UserDetails) HasID() bool {
|
|
|
|
return rnd.IsUID(m.UserUID, UserUID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new entity in the database.
|
|
|
|
func (m *UserDetails) Create() error {
|
|
|
|
return Db().Create(m).Error
|
|
|
|
}
|
|
|
|
|
2022-10-02 11:38:30 +02:00
|
|
|
// Save updates the record in the database or inserts a new record if it does not already exist.
|
2022-09-28 09:01:17 +02:00
|
|
|
func (m *UserDetails) Save() error {
|
|
|
|
return Db().Save(m).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates multiple properties in the database.
|
|
|
|
func (m *UserDetails) Updates(values interface{}) error {
|
|
|
|
return UnscopedDb().Model(m).Updates(values).Error
|
|
|
|
}
|