authentication

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Users    *database.Collection[*User]
	Sessions *database.Collection[*Session]
	// contains filtered or unexported fields
}

func Manage

func Manage(db *database.DynamicDB) *Collection

func (*Collection) Controller

func (c *Collection) Controller(opts ...Option) *Controller

func (*Collection) GetUser

func (c *Collection) GetUser(ident string) (*User, error)

func (*Collection) Signin

func (c *Collection) Signin(ident string, password string) (user *User, err error)

func (*Collection) Signup

func (c *Collection) Signup(name, email, handle, password string, isAdmin bool) (*User, error)

type Controller

type Controller struct {
	application.BaseController
	*Collection
	// contains filtered or unexported fields
}

func (*Controller) AdminOnly

func (auth *Controller) AdminOnly(app *application.App, w http.ResponseWriter, r *http.Request) bool

func (*Controller) Authenticate

func (auth *Controller) Authenticate(r *http.Request) (*User, *Session, error)

func (*Controller) CurrentSession

func (auth *Controller) CurrentSession() *Session

func (*Controller) CurrentUser

func (auth *Controller) CurrentUser() *User

func (*Controller) Forward

func (auth *Controller) Forward(name, to string) http.HandlerFunc

func (Controller) Handle

func (auth Controller) Handle(r *http.Request) application.Controller

func (Controller) HandleSignin

func (auth Controller) HandleSignin(w http.ResponseWriter, r *http.Request)

func (Controller) HandleSignout

func (auth Controller) HandleSignout(w http.ResponseWriter, r *http.Request)

func (Controller) HandleSignup

func (auth Controller) HandleSignup(w http.ResponseWriter, r *http.Request)

func (*Controller) Optional

func (auth *Controller) Optional(app *application.App, w http.ResponseWriter, r *http.Request) bool

func (*Controller) Protect

func (auth *Controller) Protect(fn http.Handler, adminOnly bool) http.HandlerFunc

func (*Controller) ProtectFunc

func (auth *Controller) ProtectFunc(h http.HandlerFunc, adminOnly bool) http.Handler

func (*Controller) Required

func (auth *Controller) Required(app *application.App, w http.ResponseWriter, r *http.Request) bool

func (*Controller) Serve

func (auth *Controller) Serve(name string, adminOnly bool) http.Handler

func (*Controller) Setup

func (auth *Controller) Setup(app *application.App)

type Option

type Option func(*Controller)

func WithCookie

func WithCookie(name string) Option

func WithSetupView

func WithSetupView(view, dest string) Option

func WithSigninHandler

func WithSigninHandler(fn func(*Controller, *User) http.HandlerFunc) Option

func WithSigninView

func WithSigninView(view, dest string) Option

func WithSignoutURL

func WithSignoutURL(url string) Option

func WithSignupHandler

func WithSignupHandler(fn func(*Controller, *User) http.HandlerFunc) Option

type Session

type Session struct {
	database.Model
	UserID string
}

func (*Session) Table

func (*Session) Table() string

func (*Session) Token

func (s *Session) Token() (string, error)

type User

type User struct {
	*Collection

	database.Model
	Avatar   string
	Name     string
	Email    string
	Handle   string
	IsAdmin  bool
	Role     string // "admin", "developer", "guest"
	PassHash []byte
}

func (*User) SetupPassword

func (user *User) SetupPassword(password string) (err error)

func (*User) Table

func (*User) Table() string

func (*User) VerifyPassword

func (user *User) VerifyPassword(password string) bool

Jump to

Keyboard shortcuts

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