mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
session + user structs, some light refactoring, user roles
This commit is contained in:
61
dbmodels/user.go
Normal file
61
dbmodels/user.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package dbmodels
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
var _ core.RecordProxy = (*Place)(nil)
|
||||
|
||||
type User struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func NewUser(record *core.Record) *User {
|
||||
i := &User{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
|
||||
func (u *User) TableName() string {
|
||||
return USERS_TABLE
|
||||
}
|
||||
|
||||
// INFO: Email is already set on the core.Record
|
||||
// TODO: We need to create a settings struct as soon as we have settings
|
||||
func (u *User) Name() string {
|
||||
return u.GetString(USERS_NAME_FIELD)
|
||||
}
|
||||
|
||||
func (u *User) SetName(name string) {
|
||||
u.Set(USERS_NAME_FIELD, name)
|
||||
}
|
||||
|
||||
func (u *User) Created() types.DateTime {
|
||||
return u.GetDateTime(CREATED_FIELD)
|
||||
}
|
||||
|
||||
func (u *User) Updated() types.DateTime {
|
||||
return u.GetDateTime(UPDATED_FIELD)
|
||||
}
|
||||
|
||||
func (u *User) Role() string {
|
||||
return u.GetString(USERS_ROLE_FIELD)
|
||||
}
|
||||
|
||||
func (u *User) SetRole(role string) {
|
||||
u.Set(USERS_ROLE_FIELD, role)
|
||||
}
|
||||
|
||||
func (u *User) Avatar() string {
|
||||
av := u.GetString(USERS_AVATAR_FIELD)
|
||||
if av != "" {
|
||||
return "/api/files/" + u.TableName() + "/" + u.Id + "/" + av
|
||||
}
|
||||
return av
|
||||
}
|
||||
|
||||
func (u *User) SetAvatar(avatar *filesystem.File) {
|
||||
u.Set(USERS_AVATAR_FIELD, avatar)
|
||||
}
|
||||
Reference in New Issue
Block a user