models

package
v0.0.0-...-6f37532 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResetDuration = 1 * time.Hour
)
View Source
const (
	DefaultSender = "support@lenslocked.com"
)
View Source
const (
	MinBytesPerToken = 32
)

Variables

This section is empty.

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
	// contains filtered or unexported fields
}

func NewEmailService

func NewEmailService(config SMTPConfig) *EmailService

func (*EmailService) ForgotPassword

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

func (*EmailService) Send

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

type PasswordReset

type PasswordReset struct {
	ID        int
	UserID    int
	Token     string
	TokenHash string
	ExpiresAt time.Time
}

type PasswordResetService

type PasswordResetService struct {
	DB            *sql.DB
	BytesPerToken int
	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 (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
	TokenHash string
}

type SessionService

type SessionService struct {
	DB            *sql.DB
	BytesPerToken int
}

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 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)

Jump to

Keyboard shortcuts

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