api

package
v0.0.0-...-d7118e0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomConfirmationCode

func RandomConfirmationCode(length int) string

RandomConfirmationCode generates a random confirmation code of a specified length using digits 0-9.

func RandomPassword

func RandomPassword(length int) string

RandomPassword generates a random password of a specified length using uppercase and lowercase letters, numbers, and special characters.

Types

type API

type API struct {
	http.Handler
	*Resources
}

func NewAPI

func NewAPI(db *sqlx.DB, logger logger.Logger) *API

func (API) AddAccountRole

func (h API) AddAccountRole(w http.ResponseWriter, r *http.Request)

func (API) AuthMiddleware

func (h API) AuthMiddleware(next http.Handler) http.Handler

func (API) AuthorizeAccount

func (h API) AuthorizeAccount(accountID int64, permission hmm.RolePermission) error

func (API) ConfirmEmail

func (h API) ConfirmEmail(w http.ResponseWriter, r *http.Request)

func (API) CreateRole

func (h API) CreateRole(w http.ResponseWriter, r *http.Request)

func (API) CreateSession

func (h API) CreateSession(w http.ResponseWriter, r *http.Request)

func (API) EditRole

func (h API) EditRole(w http.ResponseWriter, r *http.Request)

func (API) ExpireSession

func (h API) ExpireSession(w http.ResponseWriter, r *http.Request)

func (API) GetAccount

func (h API) GetAccount(w http.ResponseWriter, r *http.Request)

func (API) GetAccountRoles

func (h API) GetAccountRoles(w http.ResponseWriter, r *http.Request)

func (API) GetAccounts

func (h API) GetAccounts(w http.ResponseWriter, r *http.Request)

func (API) GetRoles

func (h API) GetRoles(w http.ResponseWriter, r *http.Request)

func (API) GetSession

func (h API) GetSession(w http.ResponseWriter, r *http.Request)

func (API) ResetPassword

func (h API) ResetPassword(w http.ResponseWriter, r *http.Request)

type Account

type Account struct {
	ID                         int64 `json:"ID"`
	FirstName, LastName, Email string
	DOB                        string `json:"DateOfBird"`
	PhoneNumber                string
	DoorCode                   string
	Gender                     string
	Active                     bool
	ConfirmedEmail             bool
	ConfirmedPhone             bool
	FailedLoginsCount          int64
	Roles                      []Role
}

Account is the restricted response body of hmm.Account see: https://stackoverflow.com/questions/46427723/golang-elegant-way-to-omit-a-json-property-from-being-serialized

func AccountView

func AccountView(a *hmm.Account, options map[string]bool) Account

func AccountsView

func AccountsView(accs hmm.Accounts, options map[string]bool) []Account

type AccountRole

type AccountRole struct {
	Account Account
	Role    Role
}

func AccountRoleView

func AccountRoleView(ar *hmm.AccountRole, options map[string]bool) AccountRole

type CreateAccountRequest

type CreateAccountRequest struct {
	FirstName   string
	LastName    string
	DOBString   string    `json:"dob"`
	DOB         time.Time `json:"-"`
	Gender      *string
	PhoneNumber *string
	Email       string
	Password    string
}

func (*CreateAccountRequest) ValidateAndNormalize

func (r *CreateAccountRequest) ValidateAndNormalize() error

type JSONError

type JSONError struct {
	Error      string
	StatusCode int
}

type Resources

type Resources struct {
	AccountService      hmm.AccountService
	SessionService      hmm.SessionService
	ConfirmationService hmm.ConfirmationService
	RoleService         hmm.RoleService
	Logger              logger.Logger
}

func (Resources) CreateAccount

func (re Resources) CreateAccount(w http.ResponseWriter, r *http.Request)

func (Resources) NotImplementedHandler

func (h Resources) NotImplementedHandler(w http.ResponseWriter, r *http.Request)

NotImplementedHandler responds with a 501 status code and a message indicating that the requested functionality has not been implemented.

func (Resources) RespondJSON

func (a Resources) RespondJSON(w http.ResponseWriter, object interface{})

func (Resources) RespondJSONError

func (a Resources) RespondJSONError(w http.ResponseWriter, errorMessage string, code int)

func (Resources) RespondText

func (a Resources) RespondText(w http.ResponseWriter, text string, code int)

func (Resources) Unmarshal

func (a Resources) Unmarshal(r *http.Request, iface interface{}) error

func (Resources) Version

func (h Resources) Version(w http.ResponseWriter, r *http.Request)

Version returns the API version.

type Role

type Role struct {
	Name          string
	Permissions   []string
	PermissionBit int
}

func RoleView

func RoleView(r *hmm.Role, options map[string]bool) Role

func RolesView

func RolesView(rs hmm.Roles, options map[string]bool) []Role

Jump to

Keyboard shortcuts

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