models

package
v0.0.0-...-a8e26b6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResetDuration = 1 * time.Hour
)
View Source
const (
	DefaultSender = "[email protected]"
)
View Source
const (
	MinBytesPerToken = 32
)

Variables

View Source
var (
	ErrEmailTaken = errors.New("models: email address is already taken")
	ErrNotFound   = errors.New("models: resource not found")
)

Functions

func Migrate

func Migrate(db *sql.DB, dir string) error

func MigrateFS

func MigrateFS(db *sql.DB, migrationsFS fs.FS, dir string) error

func Open

func Open(config PostgresConfig) (*sql.DB, error)

Types

type Email

type Email struct {
	From      string
	To        string
	Subject   string
	PlainText string
	HTML      string
}

type EmailService

type EmailService struct {
	DefaultSender string // DefaultSender is used as the default sender when there is not provided for an email.
	// contains filtered or unexported fields
}

func NewEmailService

func NewEmailService(config SMTPConfig) *EmailService

func (*EmailService) ForgotPassword

func (es *EmailService) ForgotPassword(to, resetURL string) error

func (*EmailService) Send

func (es *EmailService) Send(email Email) error

type FileError

type FileError struct {
	Issue string
}

func (FileError) Error

func (e FileError) Error() string
type Gallery struct {
	ID     int
	UserID int
	Title  string
}

type GalleryService

type GalleryService struct {
	DB *sql.DB

	// ImagesDir is the path to the directory where images are stored. Defaults to "images/".
	ImagesDir string
}

func (*GalleryService) ByID

func (service *GalleryService) ByID(id int) (*Gallery, error)

func (*GalleryService) ByUserID

func (service *GalleryService) ByUserID(userID int) ([]Gallery, error)

func (*GalleryService) Create

func (service *GalleryService) Create(title string, userID int) (*Gallery, error)

func (*GalleryService) CreateImage

func (service *GalleryService) CreateImage(id int, filename string, contents io.ReadSeeker) error

func (*GalleryService) Delete

func (service *GalleryService) Delete(id int) error

func (*GalleryService) DeleteImage

func (service *GalleryService) DeleteImage(id int, filename string) error

func (*GalleryService) Image

func (service *GalleryService) Image(id int, filename string) (Image, error)

func (*GalleryService) Images

func (service *GalleryService) Images(id int) ([]Image, error)

func (*GalleryService) Update

func (service *GalleryService) Update(gallery *Gallery) error

type Image

type Image struct {
	GalleryID int
	Path      string
	Filename  string
}

type PasswordReset

type PasswordReset struct {
	ID        int
	UserID    int
	Token     string // Only set while creating new PasswordReset. Otherwise, it is blank.
	TokenHash string
	ExpiresAt time.Time
}

type PasswordResetService

type PasswordResetService struct {
	DB           *sql.DB
	TokenManager TokenManager
	Duration     time.Duration // Amount of time that PasswordReset is valid for.
}

func (*PasswordResetService) Consume

func (service *PasswordResetService) Consume(token string) (*User, error)

func (*PasswordResetService) Create

func (service *PasswordResetService) Create(email string) (*PasswordReset, error)

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	SSLMode  string
}

func (PostgresConfig) String

func (config PostgresConfig) String() string

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     int
	Username string
	Password string
}

type Session

type Session struct {
	ID        int
	UserID    int
	Token     string // Only set while creating new session. Otherwise, it is blank.
	TokenHash string
}

type SessionService

type SessionService struct {
	DB           *sql.DB
	TokenManager TokenManager
}

func (*SessionService) Create

func (ss *SessionService) Create(userID int) (*Session, error)

func (*SessionService) Delete

func (ss *SessionService) Delete(token string) error

func (*SessionService) User

func (ss *SessionService) User(token string) (*User, error)

type TokenManager

type TokenManager struct {
	BytesPerToken int
}

func (TokenManager) New

func (tm TokenManager) New() (token, tokenHash string, err error)

type User

type User struct {
	ID           int
	Email        string
	PasswordHash string
}

type UserService

type UserService struct {
	DB *sql.DB
}

func (UserService) Authenticate

func (us UserService) Authenticate(email, password string) (*User, error)

func (*UserService) Create

func (us *UserService) Create(email, password string) (*User, error)

func (*UserService) UpdatePassword

func (us *UserService) UpdatePassword(userID int, password string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳