Documentation ¶
Index ¶
- Variables
- type Condition
- type Interactor
- func (i *Interactor) Confirm(token string) error
- func (i *Interactor) ConfirmationToken(u *User, ttl int64) (string, error)
- func (i *Interactor) Create(u *User) error
- func (i *Interactor) Delete(id string) error
- func (i *Interactor) GetByEmail(email string) (*User, error)
- func (i *Interactor) GetByID(id string) (*User, error)
- func (i *Interactor) GetList(c ...Condition) ([]*User, error)
- func (i *Interactor) ResetPassword(token string, newPassword string) error
- func (i *Interactor) ResetPasswordToken(u *User, ttl int64) (string, error)
- func (i *Interactor) Update(u *User) error
- func (i *Interactor) VerifyPassword(u *User, passwordStr string) error
- type Order
- type QuerySection
- type Repository
- func (r *Repository) Delete(id string) error
- func (r *Repository) GetByEmail(email string) (*User, error)
- func (r *Repository) GetByID(id string) (*User, error)
- func (r *Repository) GetList(c ...Condition) ([]*User, error)
- func (r *Repository) Insert(u *User) error
- func (r *Repository) Update(u *User) error
- type User
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("user not found") ErrInvalidPassword = errors.New("invalid password") ErrTakenEmail = errors.New("email is already taken") ErrEmailMissed = errors.New("email is missed") ErrNotExistedUser = errors.New("could not update not existed user") ErrCouldNotSetPassword = errors.New("could not set password") ErrInvalidToken = errors.New("invalid token string") ErrCouldNotGenerateToken = errors.New("could not generate new token") )
Predefined users package errors
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition interface { Query() string Params() []interface{} Type() QuerySection }
Condition struct
type Interactor ¶
type Interactor struct {
// contains filtered or unexported fields
}
Interactor structure
func New ¶
func New(db *sql.DB, driverName, tableName, signingKey string) *Interactor
New function is a factory which returns users Interactor instance with injected users repository Can be used as a helper to make the code shorter
func NewInteractor ¶
func NewInteractor(r UserRepository, signingKey string) *Interactor
NewInteractor factory
func (*Interactor) Confirm ¶
func (i *Interactor) Confirm(token string) error
Confirm function checks token and set confirmed=true if it's valid
func (*Interactor) ConfirmationToken ¶
func (i *Interactor) ConfirmationToken(u *User, ttl int64) (string, error)
ConfirmationToken returns confirmation token string
func (*Interactor) GetByEmail ¶
func (i *Interactor) GetByEmail(email string) (*User, error)
GetByEmail fetch user by email
func (*Interactor) GetByID ¶
func (i *Interactor) GetByID(id string) (*User, error)
GetByID fetch user by id
func (*Interactor) GetList ¶
func (i *Interactor) GetList(c ...Condition) ([]*User, error)
GetList od users with sorting and optional conditional
func (*Interactor) ResetPassword ¶
func (i *Interactor) ResetPassword(token string, newPassword string) error
ResetPassword fucntion validates token and updates password
func (*Interactor) ResetPasswordToken ¶
func (i *Interactor) ResetPasswordToken(u *User, ttl int64) (string, error)
ResetPasswordToken returns reset password token string
func (*Interactor) VerifyPassword ¶
func (i *Interactor) VerifyPassword(u *User, passwordStr string) error
VerifyPassword compare password string with user password hash, returns nil if password is valid
type Order ¶
type Order int
Order type
type QuerySection ¶
type QuerySection int
QuerySection type
const ( QsWhere QuerySection = iota + 1 QsOrderBy QsLimit QsOffset )
Predefined query section type
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository structure is implementation of UserRepository interface
func NewRepository ¶
func NewRepository(db *sql.DB, driverName, tableName string) *Repository
NewRepository factory
func (*Repository) GetByEmail ¶
func (r *Repository) GetByEmail(email string) (*User, error)
GetByEmail fetch user record by email
func (*Repository) GetByID ¶
func (r *Repository) GetByID(id string) (*User, error)
GetByID fetch user record by id
type User ¶
type User struct { ID string `db:"id" json:"id"` Email string `db:"email" json:"email"` Password string `db:"password" json:"-"` Confirmed bool `db:"confirmed" json:"confirmed"` Disabled bool `db:"disabled" json:"disabled"` CreatedAt int64 `db:"created_at" json:"created_at"` UpdatedAt *int64 `db:"updated_at" json:"updated_at,omitempty,"` }
User model structure