user

package
v0.0.0-...-3c236ea Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid email or password")
	ErrNotActive          = errors.New("the user is not active")
)

Functions

func HashPassword

func HashPassword(password string) (string, error)

Types

type DbUserRepository

type DbUserRepository struct {
	DB database.DatabaseInterface
}

func (*DbUserRepository) FindByEmail

func (r *DbUserRepository) FindByEmail(email string) (*User, error)

func (*DbUserRepository) SaveUser

func (r *DbUserRepository) SaveUser(user *User) error

type User

type User struct {
	// contains filtered or unexported fields
}

func Create

func Create(db database.DatabaseInterface, username, email, plainPassword string) (*User, error)

func CreateWithRepo

func CreateWithRepo(repo UserRepository, username, email, plainPassword string) (*User, error)

func FindByEmail

func FindByEmail(db database.DatabaseInterface, email string) (*User, error)

func FindByID

func FindByID(db database.DatabaseInterface, id int) (*User, error)

func FindByUsername

func FindByUsername(
	db database.DatabaseInterface,
	username string,
) (*User, error)

func New

func New(fields UserFields) *User

func NewUser

func NewUser(username, email, hashedPassword string, status bool) *User

func (*User) CheckPassword

func (user *User) CheckPassword(password string) error

func (*User) CreateVerificationToken

func (user *User) CreateVerificationToken() string

func (*User) GetCreatedAt

func (user *User) GetCreatedAt() (createdAt time.Time)

func (*User) GetEmail

func (user *User) GetEmail() (email string)

func (*User) GetID

func (user *User) GetID() (id int)

func (*User) GetLastLogin

func (user *User) GetLastLogin() (lastLogin time.Time)

func (*User) GetStatus

func (user *User) GetStatus() (status bool)

func (*User) GetUpdatedAt

func (user *User) GetUpdatedAt() (updatedAt time.Time)

func (*User) GetUsername

func (user *User) GetUsername() (username string)

func (*User) Login

func (user *User) Login(db database.DatabaseInterface, session sessions.Session) (err error)

func (*User) Save

func (user *User) Save(db database.DatabaseInterface) (err error)

func (*User) SetStatus

func (user *User) SetStatus(status bool)

func (*User) SetUsername

func (user *User) SetUsername(username string)

type UserFields

type UserFields struct {
	Id        int
	Username  string
	Email     string
	Password  string
	Status    bool
	CreatedAt time.Time
	UpdatedAt time.Time
	LastLogin time.Time
}

type UserRepository

type UserRepository interface {
	FindByEmail(email string) (*User, error)
	SaveUser(user *User) error
}

Jump to

Keyboard shortcuts

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