user

package
v0.0.0-...-1f9e35f Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package user provides user (related) entities and business logic.

Index

Constants

View Source
const (
	RoleAdmin = "ADMIN"
	RoleUser  = "USER"
)

Variables

This section is empty.

Functions

func ContextWithSession

func ContextWithSession(ctx context.Context, s Session) context.Context

ContextWithSession returns a new context with the provided session encapsulated.

Types

type Session

type Session struct {
	User    User
	Expires time.Time
}

Session is an entity for user sessions.

func GetSession

func GetSession(ctx context.Context) (Session, error)

GetSession returns the Session from the context. Returns an error is there's no or an invalid session in the context.

func NewSession

func NewSession(u User, expires time.Time) Session

NewSession returns an initialized user session.

func (Session) IsExpired

func (s Session) IsExpired() bool

IsExpired returns true if the session is expired.

func (Session) IsValid

func (s Session) IsValid() bool

IsValid returns true if the session is valid. The session is valid if it's not expires and contains a valid User entity for the authenticated user

func (Session) UserHasRole

func (s Session) UserHasRole(roles ...string) bool

UserHasRole returns true if the session's user has one of the provided roles.

type User

type User struct {
	ID           string    `validate:"required,uuid"`
	Name         string    `validate:"required"`
	Email        string    `validate:"required,email"`
	PasswordHash []byte    `validate:"required,notEmptyPassword"`
	Roles        []string  `validate:"required,min=1"`
	DateCreated  time.Time `validate:"required"`
	DateUpdated  time.Time `validate:"required"`
}

func New

func New(id, name, email, password string, roles []string, now time.Time) (User, error)

func NewWithID

func NewWithID(name, email, password string, roles []string, now time.Time) (User, error)

func (User) HasPassword

func (u User) HasPassword(s string) bool

func (User) Validate

func (u User) Validate() error

Directories

Path Synopsis
Package usecases provides user usecases with application logic.
Package usecases provides user usecases with application logic.

Jump to

Keyboard shortcuts

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