models

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupName

func GroupName(g string) uuid.UUID

GroupName return a uuid for the group name

func GroupSuperAdmin

func GroupSuperAdmin() uuid.UUID

GroupSuperAdmin returns the uuid for the Super Admin

func GroupTitle

func GroupTitle(g uuid.UUID) string

GroupTitle return a pretty text name for the group

Types

type GroupMembership

type GroupMembership struct {
	ID        string    `validate:"required,ulid" bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
	CreatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
	UserID    string    `validate:"required,ulid" bun:"type:CHAR(26),unique:groupmembership,notnull,nullzero"`
	User      *User     `validate:"-" bun:"rel:belongs-to,join:user_id=id"`
	GroupID   uuid.UUID `validate:"required" bun:",unique:groupmembership,notnull,nullzero"`
}

GroupMembership represents a user's membership in a group

func (*GroupMembership) BeforeAppendModel added in v0.0.5

func (gm *GroupMembership) BeforeAppendModel(_ context.Context, query bun.Query) error

BeforeAppendModel runs before a bun append operation

type User

type User struct {
	ID                string             `validate:"required,ulid" bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
	CreatedAt         time.Time          `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
	UpdatedAt         time.Time          `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
	Email             string             `validate:"-" bun:",nullzero,notnull,unique"`
	EncryptedPassword string             `validate:"-" bun:""`
	SignInCount       int                `validate:"min=0" bun:",notnull,default:0"`
	Groups            []*GroupMembership `validate:"-" bun:"rel:has-many,join:id=user_id"`
	Disabled          bool               `validate:"-" bun:",notnull,default:false"`
}

User represents a human user.

func (*User) BeforeAppendModel added in v0.0.5

func (u *User) BeforeAppendModel(_ context.Context, query bun.Query) error

BeforeAppendModel runs before a bun append operation

func (*User) CheckPasswordHash

func (u *User) CheckPasswordHash(password string) bool

CheckPasswordHash is used to validate that a given password matches the stored hash

func (*User) InGroup added in v0.0.4

func (u *User) InGroup(g ...uuid.UUID) bool

InGroup returns true if user is member of group

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword updates the user object's password hash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL