models

package
v0.0.0-...-4bcbab6 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptCipher

func DecryptCipher(cipherText string, password string) (string, error)

DecryptCipher : Decrypt the cipher with the password

func EncryptCipher

func EncryptCipher(cipherText string, password string) (string, error)

EncryptCipher : Encrypt the cipher with the password

func Hash

func Hash(password string) ([]byte, error)

Hash : Hash a string with an bcrypt hash function

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword : Verify the hashed password with the to be checked

Types

type Device

type Device struct {
	ID          uint      `gorm:"primary_key"`
	UserID      uint      `gorm:"" json:"userId"`
	Name        string    `gorm:"size:100;not null" json:"name"`
	PrivateKey  string    `gorm:"size:255;not null" json:"privateKey"`
	PublicKey   string    `gorm:"size:255;not null" json:"publicKey"`
	IPv4Address string    `gorm:"size:15;not null" json:"ipv4Address"`
	IPv6Address string    `gorm:"size:45;not null" json:"ipv6Address"`
	CreatedAt   time.Time `gorm:"precision:6" json:"createdAt"`
	UpdatedAt   time.Time `gorm:"precision:6" json:"updatedAt"`
}

Device : Device model

func (*Device) TableName

func (d *Device) TableName() string

TableName : Get the database table name

func (*Device) Validate

func (d *Device) Validate() error

Validate : Validate a device model

type Group

type Group struct {
	ID        uint         `gorm:"primary_key"`
	Name      string       `gorm:"size:255;not null;unique" json:"name"`
	Users     []*UserGroup `gorm:"association_autoupdate:false;association_autocreate:false;preload:false;foreignkey:GroupID" json:"users"` // nolint:lll
	Type      string       `gorm:"size:100;not null" json:"type"`
	CreatedAt time.Time    `gorm:"precision:6" json:"createdAt"`
	UpdatedAt time.Time    `gorm:"precision:6" json:"updatedAt"`
}

Group : Group model

func (*Group) IsMember

func (g *Group) IsMember(userID uint) bool

IsMember : Check if user is in group

func (*Group) TableName

func (g *Group) TableName() string

TableName : Get the database table name

func (*Group) Validate

func (g *Group) Validate() error

Validate : Validate the group

type User

type User struct {
	ID              uint      `gorm:"primary_key"`
	Username        string    `gorm:"size:100;not null;unique" json:"username"`
	Password        string    `gorm:"size:100;not null" json:"password"`
	ProtectPassword string    `gorm:"size:100" json:"protectPassword"`
	Cipher          string    `gorm:"size:125;not null" json:"cipher"`
	FirstName       string    `gorm:"size:100;not null" json:"firstName"`
	LastName        string    `gorm:"size 100;not null" json:"lastName"`
	Mail            string    `gorm:"size 100;not null" json:"mail"`
	Type            string    `gorm:"size 50;not null" json:"type"`
	Devices         []*Device `gorm:"foreignkey:userId" json:"devices"`
	CreatedAt       time.Time `gorm:"precision:6" json:"createdAt"`
	UpdatedAt       time.Time `gorm:"precision:6" json:"updatedAt"`
}

User : User model

func (*User) BeforeSave

func (u *User) BeforeSave() error

BeforeSave : Hook before saving the user

func (*User) Prepare

func (u *User) Prepare()

Prepare : Prepare the user

func (*User) TableName

func (*User) TableName() string

TableName : Get the table name

func (*User) Validate

func (u *User) Validate() error

Validate : Validate if the user is valid

type UserGroup

type UserGroup struct {
	GroupID uint `gorm:"not null;primary_key;auto_increment:false" json:"groupId"`
	UserID  uint `gorm:"not null;primary_key;auto_increment:false" json:"userId"`

	Group Group `gorm:"association_autoupdate:false;association_autocreate:false;preload:false;foreignkey:GroupID" json:"groups"` // nolint:lll
	User  User  `gorm:"association_autoupdate:false;association_autocreate:false;preload:false;foreignkey:UserID" json:"users"`   // nolint:lll
}

UserGroup : Mapping user to groups

func (*UserGroup) TableName

func (*UserGroup) TableName() string

TableName : Get the table name

Jump to

Keyboard shortcuts

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