models

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteEntry added in v0.2.3

func DeleteEntry(tx *gorm.DB, id string) error

DeleteEntry deleted an entry by a given ID and returns an error

func IncreaseVisitCounter added in v0.2.3

func IncreaseVisitCounter(tx *gorm.DB, link *Link) error

IncreaseVisitCounter increases the visit counter and sets the current

func IsDuplicatedEmail added in v0.2.3

func IsDuplicatedEmail(tx *gorm.DB, email string) (bool, error)

IsDuplicatedEmail returns whether a user exists with a matching email.

func IsNotFoundError added in v0.2.3

func IsNotFoundError(err error) bool

IsNotFoundError returns whether an error represents a "not found" error.

func NewAuditLogEntry added in v0.2.3

func NewAuditLogEntry(tx *gorm.DB, actor *User, action AuditAction) error

NewAuditLogEntry creates a new audit entry

func UpdateRefreshToken added in v0.2.3

func UpdateRefreshToken(tx *gorm.DB, id uint, token string) error

UpdateRefreshToken updates user by refresh token

Types

type AuditAction added in v0.2.3

type AuditAction string

AuditAction holds different action types as a string

const (
	// LoginAction is a action type
	LoginAction AuditAction = "login"
	// LogoutAction is a action type
	LogoutAction AuditAction = "logout"
	// InviteAcceptedAction is a action type
	InviteAcceptedAction AuditAction = "invite_accepted"
	// UserSignedUpAction is a action type
	UserSignedUpAction AuditAction = "user_signedup"
	// UserDeletedAction is a action type
	UserDeletedAction AuditAction = "user_deleted"
	// UserModifiedAction is a action type
	UserModifiedAction AuditAction = "user_modified"
	// UserRecoveryRequestedAction is a action type
	UserRecoveryRequestedAction AuditAction = "user_recovery_requested"
	// TokenRevokedAction is a action type
	TokenRevokedAction AuditAction = "token_revoked"
	// TokenRefreshedAction is a action type
	TokenRefreshedAction AuditAction = "token_refreshed"
)

type AuditLogEntry added in v0.2.3

type AuditLogEntry struct {
	ID         uuid.UUID    `json:"id" db:"id"`
	Timestamp  string       `json:"timestamp" db:"timestamp"`
	CreatedAt  time.Time    `json:"created_at" db:"created_at"`
	ActorID    uint         `json:"actor_id" db:"actor_id"`
	ActorEmail string       `json:"actor_email" db:"actor_email"`
	Action     AuditAction  `json:"action" db:"action"`
	LogType    auditLogType `json:"log_type" db:"log_type"`
}

AuditLogEntry is the database model for audit log entries.

func (AuditLogEntry) TableName added in v0.2.3

func (AuditLogEntry) TableName() string

TableName returns the audit tablename

type Link struct {
	ID          string     `json:"id"`
	URL         string     `json:"url"`
	RemoteAddr  string     `json:",omitempty"`
	DeletionURL string     `json:",omitempty"`
	Password    []byte     `json:",omitempty"`
	LastVisit   *time.Time `json:"last_visit, omitempty"`
	Expiration  *time.Time `json:"expiration,omitempty"`
	CreatedOn   *time.Time `json:"-"`
	VisitCount  int
}

Link is the data for our "relinker-url-shortener"

func CreateEntry added in v0.2.3

func CreateEntry(tx *gorm.DB, length int, url, id string) (*Link, error)

CreateEntry creates an entry by a given ID and returns an error

func GetLinkByID added in v0.2.3

func GetLinkByID(tx *gorm.DB, id string) (*Link, error)

GetLinkByID returns a entry and an error by the shorted ID

func LinkUpdate added in v0.2.3

func LinkUpdate(tx *gorm.DB, link *Link) (*Link, error)

LinkUpdate updates URL of Link

func LinksList(tx *gorm.DB) ([]*Link, error)

LinksList returns a List of all available Links formerly "entries"

type Stats added in v0.2.3

type Stats struct {
	Entries int `json:"entries"`
	Visits  int `json:"visits"`
}

Stats returns entries and visits for our dashboard view

func ListStats added in v0.2.3

func ListStats(tx *gorm.DB) (*Stats, error)

ListStats lists active links and clicks

type User

type User struct {
	ID           uint       `json:"id" gorm:"primary_key"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
	DeletedAt    *time.Time `json:"deleted_at" sql:"index"`
	Email        string     `json:"email" gorm:"unique;not null"`
	Password     string     `json:"password,omitempty"`
	Token        string     `json:"token,omitempty"`
	TokenExpires time.Time  `json:"token_expires"`

	RecoveryToken  string     `json:"-" db:"recovery_token"`
	RecoverySentAt *time.Time `json:"recovery_sent_at,omitempty" db:"recovery_sent_at"`

	EmailChangeToken  string     `json:"-" db:"email_change_token"`
	EmailChange       string     `json:"new_email,omitempty" db:"email_change"`
	EmailChangeSentAt *time.Time `json:"email_change_sent_at,omitempty" db:"email_change_sent_at"`
	LastSignInAt      *time.Time `json:"last_sign_in_at,omitempty" db:"last_sign_in_at"`
}

User is a user of our system

func FindUserByEmail added in v0.2.3

func FindUserByEmail(tx *gorm.DB, email string) (*User, error)

FindUserByEmail finds a user with the matching email.

func FindUserByID added in v0.2.3

func FindUserByID(tx *gorm.DB, id uint) (*User, error)

FindUserByID finds a user matching the provided ID.

func FindUserByToken added in v0.2.3

func FindUserByToken(tx *gorm.DB, token string) (*User, error)

FindUserByToken returns a user by it's refresh token

func FindUsers added in v0.2.3

func FindUsers(tx *gorm.DB) ([]*User, error)

FindUsers finds users.

func NewUser added in v0.2.4

func NewUser(tx *gorm.DB, config *config.Configuration, email, password string) (*User, string, error)

NewUser creates a new User

func (*User) Authenticate

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

func (*User) BeforeCreate

func (u *User) BeforeCreate(scope *gorm.Scope) (err error)

func (*User) BeforeSave added in v0.0.14

func (u *User) BeforeSave(scope *gorm.Scope) error

func (*User) ConfirmEmailChange added in v0.2.3

func (u *User) ConfirmEmailChange(tx *gorm.DB) error

ConfirmEmailChange confirm the change of email for a user

func (*User) Recover added in v0.2.3

func (u *User) Recover(tx *gorm.DB) error

Recover resets the recovery token

func (*User) SetEmail added in v0.2.3

func (u *User) SetEmail(tx *gorm.DB, email string) error

SetEmail updates the email of the User

func (*User) UpdatePassword added in v0.2.3

func (u *User) UpdatePassword(tx *gorm.DB, password string) error

UpdatePassword updates the given password

type UserNotFoundError added in v0.2.3

type UserNotFoundError struct{}

UserNotFoundError represents when a user is not found.

func (UserNotFoundError) Error added in v0.2.3

func (e UserNotFoundError) Error() string

Jump to

Keyboard shortcuts

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