model

package
v0.0.0-...-54d1621 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	ID        uuid.UUID `gorm:"primaryKey"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Name string `json:"name" gorm:"unique"`
}

func NewGroup

func NewGroup(name string, uuid UUID, time Time) (Group, error)

type Time

type Time interface {
	Now() time.Time
}

Time in a separate interface allows us to inject any time implementation. This is already used for testing.

type UUID

type UUID interface {
	New() uuid.UUID
}

UUID in a separate interface allows us to inject any uuid implementation. This is already used for testing.

type User

type User struct {
	ID        string    `gorm:"primaryKey"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Username          string     `json:"username"`
	Email             string     `json:"email" gorm:"unique"`
	EncryptedPassword string     `json:"-"`
	InvitedAt         *time.Time `json:"invited_at,omitempty"`
	ConfirmedID       string     `json:"confirmedID,omitempty"`
	ConfirmedAt       *time.Time `json:"confirmed_at,omitempty"`
	LastSignInAt      *time.Time `json:"last_sign_in_at,omitempty"`

	Groups []Group `gorm:"many2many:user_groups;"`
}

func NewUser

func NewUser(email string, password string) (*User, error)

func (*User) Authenticate

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

authenticate a user from a password

func (*User) Confirm

func (u *User) Confirm(confirmedID string)

Confirm resets the confimation token and the confirm timestamp confirmedID is the unique of the JWT used to confirm this account

func (*User) IsConfirmed

func (u *User) IsConfirmed() bool

IsConfirmed checks if a user has already being registered and confirmed.

Jump to

Keyboard shortcuts

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