gobwebs

package module
v0.0.0-...-4ee5816 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: BSD-3-Clause Imports: 8 Imported by: 1

README

gobwebs

!!!THIS REPO HAS BEEN MOVED!!!

For general DCVS usage reasons we've migrated this repo over to Git. Please use the new repo here:

https://git.code.netlandish.com/~netlandish/gobwebs

USE AT YOUR OWN RISK. This module, while is working in production, is not considered production ready. It is not yet version 1 ready and the API will no doubt change on core pieces. If you're adventurous then enjoy.

This is a simple set of utilities to help make it easier to write web applications in Golang. It uses the echo framework. Some of the batteries included:

  • User management
    • Login (password or magic email link)
    • Change password
    • Forgot password
    • Change email
  • Confirmation management
  • User sessions (using scs)
  • Storage (local fs or S3)
  • Custom form validation (combining echo and validator)
  • Built in async queue support (using dowork)
  • Custom email interfaces using carrier
  • Lots of template helpers
  • Built in localization

Requires Go 1.18+ and PostgreSQL.

Seriously lacking documentation, base sql tables for users and confirmations, and more. Like we said, don't use this yet. You've been warned :)

Licensed under the BSD license. See LICENSE file

Documentation

Index

Constants

View Source
const (
	// LoginTypeAuth use normal email/password auth
	LoginTypeAuth int = iota
	// LoginTypeEmail use email "magic" link for auth
	LoginTypeEmail
)

Variables

This section is empty.

Functions

func RouteDebugMiddleware

func RouteDebugMiddleware(next echo.HandlerFunc) echo.HandlerFunc

RouteDebugMiddleware prints the route name of a matched path. From: https://github.com/labstack/echo/discussions/2081#discussioncomment-2040098

func TaskIDWork

func TaskIDWork(task *work.Task)

TaskIDWork sets a task ID via the Before option for a dowork task

func TemplateHandler

func TemplateHandler(tmpl string) echo.HandlerFunc

TemplateHandler is a straight to template helper function

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock is used to pass time around, helps with test mocking

type MailChecker

type MailChecker interface {
	Check(email string, limit int) error
}

MailChecker is an interface that the email module uses to verify if a an email address is allowed to be sent email or not. Useful to track bounces, spam complaints, etc.

type Map

type Map map[string]any

Map is a global mapping type

type User

type User interface {
	GetID() uint
	GetEmail() string
	IsVerified() bool
	SetPassword(password string) error
	ComparePassword(password string) (bool, error)
	IsSuperUser() bool
	SetSuperUser(flag bool)
	IsStaff() bool
	SetStaff(flag bool)
	IsAuthenticated() bool
	SetAuthenticated(flag bool)
	SetVerified(flag bool)
}

User is a simple interface for base user object

type UserFetch

type UserFetch interface {
	GetUser() User
	FromDB(ctx context.Context, uid any, markAuth bool) (User, error)
	FromContext(c echo.Context) User

	WritePassword(ctx context.Context, user User) error

	// Helpers to customize the behavior of accounts handlers
	LoginType() int

	// Run any user checks before actually logging the user in.
	// Ie, checking if the user has `is_verified` set to true
	// Any error returned will raise an error in the LoginForm
	// validation in accounts
	ProcessLogin(c echo.Context, user User) error

	ProcessSuccessfulLogin(c echo.Context, user User) error
	ProcessSuccessfulLogout(c echo.Context) error
	ProcessSuccessfulPasswordChange(c echo.Context) error
	ProcessSuccessfulPasswordReset(c echo.Context) error
	ProcessSuccessfulEmailUpdate(c echo.Context) error
	ProcessSuccessfulEmailConfirmation(c echo.Context) error

	RedirectAfterLogin(c echo.Context, next string) string
	RedirectAfterPasswordChange(c echo.Context) string
	RedirectAfterPasswordReset(c echo.Context) string
	RedirectAfterEmailUpdate(c echo.Context) string
	RedirectAfterEmailConfirmation(c echo.Context) string

	LoginAuthTemplateVars(c echo.Context) Map
	LoginEmailTemplateVars(c echo.Context) Map
	ForgotPasswordTemplateVars(c echo.Context) Map
	ForgotPasswordConfTemplateVars(c echo.Context) Map
	ChangePasswordTemplateVars(c echo.Context) Map
	UpdateEmailTemplateVars(c echo.Context) Map
}

UserFetch is an interface to fetch User objects Main purpose is to allow external projects use custom User objects Generally used by accounts and middlewares

type WebService

type WebService interface {
	RegisterRoutes()
	RouteName(string) string
}

WebService interface for attached apps

Directories

Path Synopsis
internal
Package timezone is just a few simple utilities for dealing with timezones
Package timezone is just a few simple utilities for dealing with timezones

Jump to

Keyboard shortcuts

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