umbrella

package module
v0.0.0-...-b13d38c Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: BSD-2-Clause Imports: 15 Imported by: 0

README

go-umbrella

Login system for HTTP endpoints

Documentation

Index

Constants

View Source
const DisableCheck = 8
View Source
const DisableConfirm = 2
View Source
const DisableLogin = 4
View Source
const DisableRegister = 1
View Source
const FlagSessionActive = 1
View Source
const FlagSessionLoggedOut = 2
View Source
const FlagUserActive = 1
View Source
const FlagUserAllowLogin = 4
View Source
const FlagUserEmailConfirmed = 2
View Source
const RegisterAllowedToLogin = 32
View Source
const RegisterConfirmed = 16

Variables

This section is empty.

Functions

func GetAuthorizationBearerToken

func GetAuthorizationBearerToken(r *http.Request) string

func GetUserIDFromRequest

func GetUserIDFromRequest(r *http.Request) int64

Types

type ErrUmbrella

type ErrUmbrella struct {
	Op  string
	Err error
}

ErrUmbrella wraps original error that occurred in Err with name of the operation/step that failed, which is in Op field

func (*ErrUmbrella) Error

func (e *ErrUmbrella) Error() string

func (*ErrUmbrella) Unwrap

func (e *ErrUmbrella) Unwrap() error

type GoCRUDSession

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

GoCRUDSession is default implementation of SessionInterface using go-crud

func (*GoCRUDSession) CreateDBTable

func (g *GoCRUDSession) CreateDBTable() error

func (*GoCRUDSession) GetByKey

func (g *GoCRUDSession) GetByKey(key string) (bool, error)

func (*GoCRUDSession) GetExpiresAt

func (g *GoCRUDSession) GetExpiresAt() int64

func (*GoCRUDSession) GetFlags

func (g *GoCRUDSession) GetFlags() int

func (*GoCRUDSession) GetKey

func (g *GoCRUDSession) GetKey() string

func (*GoCRUDSession) GetUserID

func (g *GoCRUDSession) GetUserID() int

func (*GoCRUDSession) Save

func (g *GoCRUDSession) Save() error

func (*GoCRUDSession) SetExpiresAt

func (g *GoCRUDSession) SetExpiresAt(exp int64)

func (*GoCRUDSession) SetFlags

func (g *GoCRUDSession) SetFlags(flags int)

func (*GoCRUDSession) SetKey

func (g *GoCRUDSession) SetKey(k string)

func (*GoCRUDSession) SetUserID

func (g *GoCRUDSession) SetUserID(i int)

type GoCRUDUser

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

GoCRUDUser is default implementation of UserInterface using go-crud

func (*GoCRUDUser) CreateDBTable

func (g *GoCRUDUser) CreateDBTable() error

func (*GoCRUDUser) GetByEmail

func (g *GoCRUDUser) GetByEmail(email string) (bool, error)

func (*GoCRUDUser) GetByEmailActivationKey

func (g *GoCRUDUser) GetByEmailActivationKey(key string) (bool, error)

func (*GoCRUDUser) GetByID

func (g *GoCRUDUser) GetByID(id int) (bool, error)

func (*GoCRUDUser) GetEmail

func (g *GoCRUDUser) GetEmail() string

func (*GoCRUDUser) GetEmailActivationKey

func (g *GoCRUDUser) GetEmailActivationKey() string

func (*GoCRUDUser) GetExtraField

func (g *GoCRUDUser) GetExtraField(n string) string

func (*GoCRUDUser) GetFlags

func (g *GoCRUDUser) GetFlags() int

func (*GoCRUDUser) GetID

func (g *GoCRUDUser) GetID() int

func (*GoCRUDUser) GetPassword

func (g *GoCRUDUser) GetPassword() string

func (*GoCRUDUser) Save

func (g *GoCRUDUser) Save() error

func (*GoCRUDUser) SetEmail

func (g *GoCRUDUser) SetEmail(e string)

func (*GoCRUDUser) SetEmailActivationKey

func (g *GoCRUDUser) SetEmailActivationKey(k string)

func (*GoCRUDUser) SetExtraField

func (g *GoCRUDUser) SetExtraField(n string, v string)

func (*GoCRUDUser) SetFlags

func (g *GoCRUDUser) SetFlags(flags int)

func (*GoCRUDUser) SetPassword

func (g *GoCRUDUser) SetPassword(p string)

type HTTPResponse

type HTTPResponse struct {
	OK      int8                   `json:"ok"`
	ErrText string                 `json:"err_text"`
	Data    map[string]interface{} `json:"data"`
}

HTTPResponse is a base structure for all the HTTP responses from HTTP endpoints

func NewHTTPResponse

func NewHTTPResponse(ok int8, errText string) HTTPResponse

NewHTTPResponse returns new HTTPResponse object

type Hooks

type Hooks struct {
	PostRegisterSuccess func(http.ResponseWriter, string) bool
	PostConfirmSuccess  func(http.ResponseWriter) bool
	PostLoginSuccess    func(http.ResponseWriter, string, string, int64) bool
	PostCheckSuccess    func(http.ResponseWriter, string, int64, bool) bool
	PostLogoutSuccess   func(http.ResponseWriter, string) bool
}

type Interfaces

type Interfaces struct {
	User    func() UserInterface
	Session func() SessionInterface
}

type JWTConfig

type JWTConfig struct {
	Key               string
	ExpirationMinutes int
	Issuer            string
}

type Session

type Session struct {
	ID        int    `json:"session_id"`
	Flags     int    `json:"flags"`
	Key       string `json:"key" crud:"uniq lenmin:32 lenmax:2000"`
	ExpiresAt int64  `json:"expires_at"`
	UserID    int    `json:"user_id" crud:"req"`
}

type SessionInterface

type SessionInterface interface {
	CreateDBTable() error

	GetKey() string
	SetKey(string)
	GetExpiresAt() int64
	SetExpiresAt(int64)
	GetUserID() int
	SetUserID(int)
	GetFlags() int
	SetFlags(int)

	Save() error
	GetByKey(string) (bool, error)
}

type Umbrella

type Umbrella struct {
	Hooks           *Hooks
	Interfaces      *Interfaces
	Flags           int
	UserExtraFields []UserExtraField
	// contains filtered or unexported fields
}

func NewUmbrellaWithDB

func NewUmbrellaWithDB(dbConn *sql.DB, tblPrefix string, jwtConfig *JWTConfig) *Umbrella

func (Umbrella) CreateDBTables

func (u Umbrella) CreateDBTables() *ErrUmbrella

func (Umbrella) GetHTTPHandler

func (u Umbrella) GetHTTPHandler(uri string) http.Handler

func (Umbrella) GetHTTPHandlerWrapper

func (u Umbrella) GetHTTPHandlerWrapper(next http.Handler) http.Handler

type User

type User struct {
	ID                 int    `json:"user_id"`
	Flags              int    `json:"flags"`
	Name               string `json:"name" crud:"lenmin:0 lenmax:50"`
	Email              string `json:"email" crud:"req"`
	Password           string `json:"password"`
	EmailActivationKey string `json:"email_activation_key" crud:""`
	CreatedAt          int    `json:"created_at"`
	CreatedByUserID    int    `json:"created_by_user_id"`
}

type UserExtraField

type UserExtraField struct {
	Name         string
	RegExp       *regexp.Regexp
	DefaultValue string
}

type UserInterface

type UserInterface interface {
	CreateDBTable() error

	GetID() int
	GetEmail() string
	SetEmail(string)
	GetPassword() string
	SetPassword(string)
	GetEmailActivationKey() string
	SetEmailActivationKey(string)
	GetFlags() int
	SetFlags(int)
	GetExtraField(n string) string
	SetExtraField(n string, v string)

	Save() error
	GetByID(int) (bool, error)
	GetByEmail(string) (bool, error)
	GetByEmailActivationKey(string) (bool, error)
}

Jump to

Keyboard shortcuts

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