1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2024-11-24 17:07:00 +02:00
pocketbase/models/user.go

48 lines
1016 B
Go
Raw Normal View History

2022-07-06 23:19:05 +02:00
package models
import (
"encoding/json"
"github.com/pocketbase/pocketbase/tools/types"
)
var _ Model = (*User)(nil)
const (
// The name of the system user profiles collection.
ProfileCollectionName = "profiles"
// The name of the user field from the system user profiles collection.
ProfileCollectionUserFieldName = "userId"
)
type User struct {
BaseAccount
Verified bool `db:"verified" json:"verified"`
LastVerificationSentAt types.DateTime `db:"lastVerificationSentAt" json:"lastVerificationSentAt"`
// profile rel
Profile *Record `db:"-" json:"profile"`
}
func (m *User) TableName() string {
return "_users"
}
// AsMap returns the current user data as a plain map
// (including the profile relation, if loaded).
func (m *User) AsMap() (map[string]any, error) {
userBytes, err := json.Marshal(m)
if err != nil {
return nil, err
}
result := map[string]any{}
if err := json.Unmarshal(userBytes, &result); err != nil {
return nil, err
}
return result, nil
}