userstore

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

README

UserStore Open in Gitpod

Tests Status Go Report Card PkgGoDev

UserStore is a robust user management package.

TaskStore supports multiple database storages (SQLite, MySQL, or PostgreSQL)

License

This project is licensed under the GNU General Public License version 3 (GPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/gpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Installation

go get github.com/gouniverse/userstore

Setup

userStore, err = taskstore.NewStore(taskstore.NewStoreOptions{
	DB:                 databaseInstance,
    UserTableName:      "user",
	AutomigrateEnabled: true,
	DebugEnabled:       false,
})

if err != nil {
	return errors.Join(errors.New("userstore.NewStore"), err)
}

Examples

user := userstore.NewUser().
    SetStatus(userstore.USER_STATUS_ACTIVE).
    SetFirstName("John").
    SetLastName("Doe").
    SetEmail("test@test.com")

err := userStore.UserCreate(user)

if err != nil {
	return errors.New("user failed to create")
}

Documentation

Index

Constants

View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_DELETED_AT = "deleted_at"
View Source
const COLUMN_EMAIL = "email"
View Source
const COLUMN_FIRST_NAME = "first_name"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_LAST_NAME = "last_name"
View Source
const COLUMN_ROLE = "role"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const USER_ROLE_ADMINISTRATOR = "administrator"
View Source
const USER_ROLE_MANAGER = "manager"
View Source
const USER_ROLE_SUPERUSER = "superuser"
View Source
const USER_ROLE_USER = "user"
View Source
const USER_STATUS_ACTIVE = "active"
View Source
const USER_STATUS_DELETED = "deleted"
View Source
const USER_STATUS_INACTIVE = "inactive"
View Source
const USER_STATUS_UNVERIFIED = "unverified"

Variables

This section is empty.

Functions

func UserNoImageUrl

func UserNoImageUrl() string

Types

type NewStoreOptions

type NewStoreOptions struct {
	UserTableName      string
	DB                 *sql.DB
	DbDriverName       string
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions define the options for creating a new block store

type Store

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

func NewStore

func NewStore(opts NewStoreOptions) (*Store, error)

NewStore creates a new block store

func (*Store) AutoMigrate

func (store *Store) AutoMigrate() error

AutoMigrate auto migrate

func (*Store) EnableDebug

func (st *Store) EnableDebug(debug bool)

EnableDebug - enables the debug option

func (*Store) UserCount

func (store *Store) UserCount(options UserQueryOptions) (int64, error)

func (*Store) UserCreate

func (store *Store) UserCreate(user UserInterface) error

func (*Store) UserDelete

func (store *Store) UserDelete(user UserInterface) error

func (*Store) UserDeleteByID

func (store *Store) UserDeleteByID(id string) error

func (*Store) UserFindByEmail

func (store *Store) UserFindByEmail(email string) (UserInterface, error)

func (*Store) UserFindByEmailOrCreate

func (store *Store) UserFindByEmailOrCreate(email string, createStatus string) (UserInterface, error)

UserFindByEmailOrCreate - finds by email or creates a user (with active status)

func (*Store) UserFindByID

func (store *Store) UserFindByID(id string) (UserInterface, error)

func (*Store) UserList

func (store *Store) UserList(options UserQueryOptions) ([]UserInterface, error)

func (*Store) UserSoftDelete

func (store *Store) UserSoftDelete(user UserInterface) error

func (*Store) UserSoftDeleteByID

func (store *Store) UserSoftDeleteByID(id string) error

func (*Store) UserUpdate

func (store *Store) UserUpdate(user UserInterface) error

type StoreInterface

type StoreInterface interface {
	AutoMigrate() error
	EnableDebug(debug bool)
	UserCreate(user UserInterface) error
	UserDelete(user UserInterface) error
	UserDeleteByID(id string) error
	UserFindByID(userID string) (UserInterface, error)
	UserList(options UserQueryOptions) ([]UserInterface, error)
	UserSoftDelete(user UserInterface) error
	UserSoftDeleteByID(id string) error
	UserUpdate(user UserInterface) error
}

type TimezoneQueryOptions

type TimezoneQueryOptions struct {
	ID        string
	Status    string
	StatusIn  []string
	UserCode  string
	Timezone  string
	Offset    int
	Limit     int
	SortOrder string
	SortBy    string
	CountOnly bool
}

type User

type User struct {
	dataobject.DataObject
}

func (*User) BusinessName

func (o *User) BusinessName() string

func (*User) Country

func (o *User) Country() string

func (*User) CreatedAt

func (o *User) CreatedAt() string

func (*User) CreatedAtCarbon

func (o *User) CreatedAtCarbon() carbon.Carbon

func (*User) DeletedAt

func (o *User) DeletedAt() string

func (*User) Email

func (o *User) Email() string

func (*User) FirstName

func (o *User) FirstName() string

func (*User) ID

func (o *User) ID() string

func (*User) IsActive

func (o *User) IsActive() bool

func (*User) IsAdministrator

func (o *User) IsAdministrator() bool

func (*User) IsDeleted

func (o *User) IsDeleted() bool

func (*User) IsInactive

func (o *User) IsInactive() bool

func (*User) IsManager

func (o *User) IsManager() bool

func (*User) IsRegistrationCompleted

func (o *User) IsRegistrationCompleted() bool

IsRegistrationCompleted checks if the user registration is incomplete.

Registration is considered incomplete if the user's first name or last name is empty.

Parameters: - authUser: a pointer to a userstore.User object representing the authenticated user.

Returns: - bool: true if the user registration is incomplete, false otherwise.

func (*User) IsSuperuser

func (o *User) IsSuperuser() bool

func (*User) IsUnverified

func (o *User) IsUnverified() bool

func (*User) LastName

func (o *User) LastName() string

func (*User) Memo

func (o *User) Memo() string

func (*User) Meta

func (o *User) Meta(name string) string

func (*User) Metas

func (o *User) Metas() (map[string]string, error)

func (*User) MiddleNames

func (o *User) MiddleNames() string

func (*User) Password

func (o *User) Password() string

func (*User) PasswordCompare

func (o *User) PasswordCompare(password string) bool

func (*User) Phone

func (o *User) Phone() string

func (*User) ProfileImageOrDefaultUrl

func (o *User) ProfileImageOrDefaultUrl() string

func (*User) ProfileImageUrl

func (o *User) ProfileImageUrl() string

func (*User) Role

func (o *User) Role() string

func (*User) SetBusinessName

func (o *User) SetBusinessName(businessName string) UserInterface

func (*User) SetCountry

func (o *User) SetCountry(country string) UserInterface

func (*User) SetCreatedAt

func (o *User) SetCreatedAt(createdAt string) UserInterface

func (*User) SetDeletedAt

func (o *User) SetDeletedAt(deletedAt string) UserInterface

func (*User) SetEmail

func (o *User) SetEmail(email string) UserInterface

func (*User) SetFirstName

func (o *User) SetFirstName(firstName string) UserInterface

func (*User) SetID

func (o *User) SetID(id string) UserInterface

func (*User) SetLastName

func (o *User) SetLastName(lastName string) UserInterface

func (*User) SetMemo

func (o *User) SetMemo(memo string) UserInterface

func (*User) SetMeta

func (o *User) SetMeta(name string, value string) error

func (*User) SetMetas

func (o *User) SetMetas(metas map[string]string) error

SetMetas stores metas as json string Warning: it overwrites any existing metas

func (*User) SetMiddleNames

func (o *User) SetMiddleNames(middleNames string) UserInterface

func (*User) SetPassword

func (o *User) SetPassword(password string) UserInterface

SetPassword sets the password as provided, if you want it hashed use SetPasswordAndHash() method

func (*User) SetPasswordAndHash

func (o *User) SetPasswordAndHash(password string) error

SetPasswordAndHash hashes the password before saving

func (*User) SetPhone

func (o *User) SetPhone(phone string) UserInterface

func (*User) SetProfileImageUrl

func (o *User) SetProfileImageUrl(imageUrl string) UserInterface

func (*User) SetRole

func (o *User) SetRole(role string) UserInterface

func (*User) SetStatus

func (o *User) SetStatus(status string) UserInterface

func (*User) SetTimezone

func (o *User) SetTimezone(timezone string) UserInterface

func (*User) SetUpdatedAt

func (o *User) SetUpdatedAt(updatedAt string) UserInterface

func (*User) Status

func (o *User) Status() string

func (*User) Timezone

func (o *User) Timezone() string

func (*User) UpdatedAt

func (o *User) UpdatedAt() string

func (*User) UpdatedAtCarbon

func (o *User) UpdatedAtCarbon() carbon.Carbon

func (*User) UpsertMetas

func (o *User) UpsertMetas(metas map[string]string) error

type UserInterface

type UserInterface interface {
	Data() map[string]string
	DataChanged() map[string]string
	MarkAsNotDirty()

	IsActive() bool
	IsDeleted() bool
	IsInactive() bool
	IsUnverified() bool
	IsAdministrator() bool
	IsManager() bool
	IsSuperuser() bool
	IsRegistrationCompleted() bool
	BusinessName() string
	SetBusinessName(businessName string) UserInterface
	Country() string
	SetCountry(country string) UserInterface
	CreatedAt() string
	CreatedAtCarbon() carbon.Carbon
	SetCreatedAt(createdAt string) UserInterface
	DeletedAt() string
	SetDeletedAt(deletedAt string) UserInterface
	Email() string
	SetEmail(email string) UserInterface
	ID() string
	SetID(id string) UserInterface
	FirstName() string
	SetFirstName(firstName string) UserInterface
	LastName() string
	SetLastName(lastName string) UserInterface
	Memo() string
	SetMemo(memo string) UserInterface
	Meta(name string) string
	SetMeta(name string, value string) error
	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error
	MiddleNames() string
	SetMiddleNames(middleNames string) UserInterface
	Password() string
	SetPassword(password string) UserInterface
	Phone() string
	SetPhone(phone string) UserInterface
	ProfileImageUrl() string
	SetProfileImageUrl(profileImageUrl string) UserInterface
	Role() string
	SetRole(role string) UserInterface
	Timezone() string
	SetTimezone(timezone string) UserInterface
	Status() string
	SetStatus(status string) UserInterface
	PasswordCompare(password string) bool
	UpdatedAt() string
	UpdatedAtCarbon() carbon.Carbon
	SetUpdatedAt(updatedAt string) UserInterface
}

func NewUser

func NewUser() UserInterface

func NewUserFromExistingData

func NewUserFromExistingData(data map[string]string) UserInterface

type UserQueryOptions

type UserQueryOptions struct {
	ID           string
	IDIn         []string
	Status       string
	StatusIn     []string
	Email        string
	CreatedAtGte string
	CreatedAtLte string
	Offset       int
	Limit        int
	SortOrder    string
	OrderBy      string
	CountOnly    bool
	WithDeleted  bool
}

Jump to

Keyboard shortcuts

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