utils

package
v0.0.0-...-6eca15d Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoToken      = errors.New("token not found")
	ErrInvalidToken = errors.New("invalid token")
)

Functions

func NewDB

func NewDB(config DatabaseConfig) (bucket *gocb.Bucket, err error)

NewDB Initialises the connection to the database

Types

type AFCAccessClaims

type AFCAccessClaims struct {
	Id   uint64 `json:"id"`
	Role string `json:"role"`
	jwt.StandardClaims
}

type AccessClaims

type AccessClaims struct {
	UserID      int      `json:"id"`
	Role        string   `json:"role"`
	Permissions []string `json:"perms"`
	jwt.StandardClaims
}

AccessClaims represents an identifiable JWT

type Accesser

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

func NewAccesser

func NewAccesser(conf AccesserConfig) *Accesser

NewAccesser allows the validation of JWT tokens both as headers and as cookies

func (*Accesser) AFCAdminMiddleware

func (a *Accesser) AFCAdminMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func (*Accesser) AFCAuthMiddleware

func (a *Accesser) AFCAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AFCAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AdminAuthMiddleware

func (a *Accesser) AdminAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AdminAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AdminInitAuthMiddleware

func (a *Accesser) AdminInitAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AdminInitAuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) AuthMiddleware

func (a *Accesser) AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AuthMiddleware checks a HTTP request for a valid token either in the header or cookie

func (*Accesser) FindAdminToken

func (a *Accesser) FindAdminToken(r *http.Request) bool

FindAdminToken will return the claims from an AFC access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAFCToken

func (a *Accesser) GetAFCToken(r *http.Request) (*AFCAccessClaims, error)

GetAFCToken will return the claims from an AFC access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAdminToken

func (a *Accesser) GetAdminToken(r *http.Request) (*jwt.Token, error)

GetAdminToken will return the claims from an admin access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetAdminTokenKIDAndClaims

func (a *Accesser) GetAdminTokenKIDAndClaims(r *http.Request) (string, *jwt.StandardClaims, error)

GetAdminTokenKIDAndClaims will return the claims from an admin access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) GetToken

func (a *Accesser) GetToken(r *http.Request) (*AccessClaims, error)

GetToken will return the claims from an access token JWT

First will check the Authorization header, if unset will check the access cookie

func (*Accesser) NilMiddleware

func (a *Accesser) NilMiddleware(next echo.HandlerFunc) echo.HandlerFunc

NilMiddleware checks a HTTP request for a valid token either in the header or cookie

type AccesserConfig

type AccesserConfig struct {
	AccessCookieName string
	SigningKey       []byte
	DomainName       string
	Admin            Admin
}

type Admin

type Admin struct {
	AdminAccessCookieName, Key0, Key1, Key2, Key3, TOTP string
}

type AdminRequest

type AdminRequest struct {
	Key0     string `json:"key_0"`
	Key1     string `json:"key_1"`
	Key2     string `json:"key_2"`
	Key3     string `json:"key_3"`
	TOTPCode string `json:"totp_code"`
}

type AdminResponse

type AdminResponse struct {
	JWTToken string `json:"jwt_token"`
}

type Config

type Config struct {
	Host     string
	Port     int
	Username string
	Password string
	Defaults Defaults
}

Config represents a configuration to connect to an SMTP server

type DatabaseConfig

type DatabaseConfig struct {
	Host     string
	SSLMode  string
	Bucket   string
	Username string
	Password string
}

DatabaseConfig represents a configuration to connect to an SQL database

type Defaults

type Defaults struct {
	DefaultTo   string
	DefaultCC   []string
	DefaultBCC  []string
	DefaultFrom string
}

Defaults is the default values for the mailer if none are explicitly mentioned

type Error

type Error struct {
	Error string `json:"error"`
}

type Mail

type Mail struct {
	Subject string
	To      string
	Cc      []string
	Bcc     []string
	From    string
	Error   error
	Tpl     *template.Template
	TplData interface{}
}

Mail represents an email to be sent

type Mailer

type Mailer struct {
	*mail.SMTPClient
	Defaults Defaults
}

Mailer is the struct that is used to send mail, can only be used once connected to mailer

func (*Mailer) CheckSendable

func (m *Mailer) CheckSendable(item Mail) error

CheckSendable verifies that the email can be sent

func (*Mailer) SendMail

func (m *Mailer) SendMail(item Mail) error

SendMail sends a template email

type MailerInit

type MailerInit struct {
	SMTPServer mail.SMTPServer
	Defaults   Defaults
}

MailerInit is the config store for the mailer, can be initialised once then connected multiple times

func NewMailer

func NewMailer(config Config) *MailerInit

NewMailer creates a new SMTP client

func (*MailerInit) ConnectMailer

func (m *MailerInit) ConnectMailer() *Mailer

ConnectMailer connects to the mail server

type Permission

type Permission struct {
	Name string `json:"name"`
}

Permission represents the permissions that a user has

Jump to

Keyboard shortcuts

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