models

package
v0.0.0-...-9edd450 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResetDuration = 1 * time.Hour
View Source
const DefaultSender = "support@toucan.com"

Variables

View Source
var (
	ErrNotFound        = errors.New("email or password was wrong")
	ErrGalleryNotFound = errors.New("Gallery not found")
)

Functions

func MigrateFS

func MigrateFS(migrationFS fs.FS, dir string) error

func Open

func Open(config PostgresConfig) (*pgxpool.Pool, error)

Types

type Email

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

type EmailService

type EmailService struct {
	DefaultSender string
	// contains filtered or unexported fields
}

func NewEmailService

func NewEmailService() *EmailService

func (EmailService) ForgotPassword

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

func (*EmailService) Send

func (es *EmailService) Send(email Email) error
type Gallery struct {
	ID     int
	UserID int
	Title  string
}

type GalleryService

type GalleryService struct {
	DB *pgxpool.Pool

	ImageDir string
}

func (*GalleryService) Create

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

func (*GalleryService) CreateImage

func (g *GalleryService) CreateImage(galleryID int, filename string, contents io.Reader) error

func (*GalleryService) DeleteGalleryByID

func (g *GalleryService) DeleteGalleryByID(id int) error

func (*GalleryService) DeleteImage

func (g *GalleryService) DeleteImage(galleryID int, filename string) error

func (*GalleryService) GetGalleriesByUserID

func (g *GalleryService) GetGalleriesByUserID(userID int) ([]Gallery, error)

GetGalleriesByUserID returns all galleries for a given user

func (*GalleryService) GetGalleryByID

func (g *GalleryService) GetGalleryByID(id int) (*Gallery, error)

func (*GalleryService) Image

func (g *GalleryService) Image(galleryID int, filename string) (Image, error)

func (*GalleryService) Images

func (g *GalleryService) Images(galleryID int) ([]Image, error)

func (*GalleryService) UpdateGallery

func (g *GalleryService) UpdateGallery(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
	TokenHash string
	ExpiresAt time.Time
}

type PasswordResetService

type PasswordResetService struct {
	DB       *pgxpool.Pool
	Duration time.Duration
}

func (*PasswordResetService) Consume

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

func (*PasswordResetService) Create

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

type PostgresConfig

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

func DefaultPostgresConfig

func DefaultPostgresConfig() PostgresConfig

func (PostgresConfig) String

func (cfg PostgresConfig) String() string

type SMTPConfig

type SMTPConfig struct {
	HOST     string
	PORT     int
	Username string
	Password string
}

SMTPConfig load field from env

type Session

type Session struct {
	ID int

	Token     string
	TokenHash string
	// contains filtered or unexported fields
}

type SessionService

type SessionService struct {
	DB *pgxpool.Pool
}

func (*SessionService) Create

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

func (*SessionService) Delete

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

func (*SessionService) User

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

type User

type User struct {
	ID           int
	Email        string
	PasswordHash string
}

type UserService

type UserService struct {
	DB *pgxpool.Pool
}

func (*UserService) Authenticate

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

func (*UserService) CheckUserExist

func (us *UserService) CheckUserExist(email string) (bool, error)

check user exists

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