user

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 7 Imported by: 0

README

tinywasm/user

User management library for the tinywasm ecosystem. Handles user entities, password authentication, OAuth providers (Google, Microsoft), LAN (local network) authentication by RUT + IP, and session management.

Documentation

Note: RBAC is integrated into the User module (see ARCHITECTURE.md).

Diagrams

Initialization

import "github.com/tinywasm/user/authority"

// ...

// Initialize the user module directly with an ORM db instance
m, err := authority.New(db, user.Config{
    CookieName: "session_id", // default: "session"
    TokenTTL:   86400,        // default: 86400 (24h)
    TrustProxy: true,         // default: false
    JWTSecret:  []byte("your-secret"), // Required for JWT/Bearer modes
})

Production Wiring

tinywasm/user handles authentication flows, while views belong to the consumer.

  1. Mount API: Call m.MountAPI(router) to publish standard authentication routes (POST /login, POST /logout, /oauth/:provider).
  2. Bootstrap: Call m.Bootstrap(Seed) on startup to ensure a first user and their initial role/permissions exist.
  3. Consumer Views: The application builds its own login page using form.New(&user.LoginData{}) and posts to user.PathLogin using JSON.
  4. Protect Routes: Inject m.Authenticate() (middleware) and m.Can (authorization) into your host router.
  5. Client-side gating: Use the me MCP tool to retrieve user profile and permissions for cosmetic UI gating.

Status

Implementation complete. Ready for production wiring.

Documentation

Index

Constants

View Source
const (
	PathLogin      = "/login"
	PathLogout     = "/logout"
	PathAfterLogin = "/"
)
View Source
const (
	OpMe         = "me"          // authenticated caller's profile
	OpListUsers  = "list_users"  // admin: list users
	OpUpsertUser = "upsert_user" // admin: create (Id=="") or update
	OpDeleteUser = "delete_user" // admin: delete by record
)

Op names — shared vocabulary between the wasm view and the server module.

View Source
const TopicSecurity = "user.security"

TopicSecurity is the events topic every SecurityEvent is published on.

Variables

View Source
var (
	ErrInvalidCredentials = fmt.Err("access", "denied")             // EN: Access Denied                    / ES: Acceso Denegado
	ErrSuspended          = fmt.Err("user", "suspended")            // EN: User Suspended                   / ES: Usuario Suspendido
	ErrEmailTaken         = fmt.Err("email", "registered")          // EN: Email Registered                 / ES: Correo electrónico Registrado
	ErrWeakPassword       = fmt.Err("password", "weak")             // EN: Password Weak                    / ES: Contraseña Débil
	ErrSessionExpired     = fmt.Err("token", "expired")             // EN: Token Expired                    / ES: Token Expirado
	ErrNotFound           = fmt.Err("user", "not", "found")         // EN: User Not Found                   / ES: Usuario No Encontrado
	ErrProviderNotFound   = fmt.Err("provider", "not", "found")     // EN: Provider Not Found               / ES: Proveedor No Encontrado
	ErrInvalidOAuthState  = fmt.Err("state", "invalid")             // EN: State Invalid                    / ES: Estado Inválido
	ErrCannotUnlink       = fmt.Err("identity", "cannot", "unlink") // EN: Identity Cannot Unlink           / ES: Identidad No puede Desvincular
	ErrInvalidRUT         = fmt.Err("rut", "invalid")               // EN: Rut Invalid                      / ES: Rut Inválido
	ErrRUTTaken           = fmt.Err("rut", "registered")            // EN: Rut Registered                   / ES: Rut Registrado
	ErrIPTaken            = fmt.Err("ip", "registered")             // EN: Ip Registered                    / ES: Ip Registrado
)
View Source
var IdentityModel = model.Definition{
	Name: "identity",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "user_id", Type: model.Text(), DB: &model.FieldDB{RefColumn: "id"}, Ref: &UserModel},
		{Name: "provider", Type: model.Text()},
		{Name: "provider_id", Type: model.Text()},
		{Name: "email", Type: model.Text()},
		{Name: "created_at", Type: model.Int()},
	},
}
View Source
var Identity_ = struct {
	Id         string
	UserId     string
	Provider   string
	ProviderId string
	Email      string
	CreatedAt  string
}{
	Id:         "id",
	UserId:     "user_id",
	Provider:   "provider",
	ProviderId: "provider_id",
	Email:      "email",
	CreatedAt:  "created_at",
}
View Source
var LANIPModel = model.Definition{
	Name: "lanip",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "user_id", Type: model.Text(), DB: &model.FieldDB{RefColumn: "id"}, Ref: &UserModel},
		{Name: "ip", Type: model.Text()},
		{Name: "label", Type: model.Text()},
		{Name: "created_at", Type: model.Int()},
	},
}
View Source
var LANIP_ = struct {
	Id        string
	UserId    string
	Ip        string
	Label     string
	CreatedAt string
}{
	Id:        "id",
	UserId:    "user_id",
	Ip:        "ip",
	Label:     "label",
	CreatedAt: "created_at",
}
View Source
var LoginDataModel = model.Definition{
	Name: "login_data",
	Fields: model.Fields{
		{Name: "email", Type: input.Email(), NotNull: true},
		{Name: "password", Type: input.Password(), NotNull: true},
	},
}
View Source
var OAuthStateModel = model.Definition{
	Name: "oauth_state",
	Fields: model.Fields{
		{Name: "state", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "provider", Type: model.Text()},
		{Name: "expires_at", Type: model.Int()},
		{Name: "created_at", Type: model.Int()},
	},
}
View Source
var OAuthState_ = struct {
	State     string
	Provider  string
	ExpiresAt string
	CreatedAt string
}{
	State:     "state",
	Provider:  "provider",
	ExpiresAt: "expires_at",
	CreatedAt: "created_at",
}
View Source
var PasswordDataModel = model.Definition{
	Name: "password_data",
	Fields: model.Fields{
		{Name: "current", Type: input.Password(), NotNull: true},
		{Name: "new", Type: input.Password(), NotNull: true},
		{Name: "confirm", Type: input.Password(), NotNull: true},
	},
}
View Source
var PermissionModel = model.Definition{
	Name: "permission",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "name", Type: model.Text()},
		{Name: "resource", Type: model.Text()},
		{Name: "action", Type: model.Text()},
	},
}
View Source
var Permission_ = struct {
	Id       string
	Name     string
	Resource string
	Action   string
}{
	Id:       "id",
	Name:     "name",
	Resource: "resource",
	Action:   "action",
}
View Source
var ProfileDataModel = model.Definition{
	Name: "profile_data",
	Fields: model.Fields{
		{Name: "name", Type: input.Text(), NotNull: true},
		{Name: "phone", Type: input.Phone()},
	},
}
View Source
var RegisterDataModel = model.Definition{
	Name: "register_data",
	Fields: model.Fields{
		{Name: "name", Type: input.Text(), NotNull: true},
		{Name: "email", Type: input.Email(), NotNull: true},
		{Name: "password", Type: input.Password(), NotNull: true},
		{Name: "phone", Type: input.Phone()},
	},
}
View Source
var RoleModel = model.Definition{
	Name: "role",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "code", Type: model.Text()},
		{Name: "name", Type: model.Text()},
		{Name: "description", Type: model.Text()},
	},
}
View Source
var RolePermissionModel = model.Definition{
	Name: "role_permission",
	Fields: model.Fields{
		{Name: "role_id", Type: model.Text(), DB: &model.FieldDB{PK: true, RefColumn: "id"}, Ref: &RoleModel},
		{Name: "permission_id", Type: model.Text(), DB: &model.FieldDB{PK: true, RefColumn: "id"}, Ref: &PermissionModel},
	},
}
View Source
var RolePermission_ = struct {
	RoleId       string
	PermissionId string
}{
	RoleId:       "role_id",
	PermissionId: "permission_id",
}
View Source
var Role_ = struct {
	Id          string
	Code        string
	Name        string
	Description string
}{
	Id:          "id",
	Code:        "code",
	Name:        "name",
	Description: "description",
}
View Source
var SessionModel = model.Definition{
	Name: "session",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "user_id", Type: model.Text(), DB: &model.FieldDB{RefColumn: "id"}, Ref: &UserModel},
		{Name: "expires_at", Type: model.Int()},
		{Name: "ip", Type: model.Text()},
		{Name: "user_agent", Type: model.Text()},
		{Name: "created_at", Type: model.Int()},
	},
}
View Source
var Session_ = struct {
	Id        string
	UserId    string
	ExpiresAt string
	Ip        string
	UserAgent string
	CreatedAt string
}{
	Id:        "id",
	UserId:    "user_id",
	ExpiresAt: "expires_at",
	Ip:        "ip",
	UserAgent: "user_agent",
	CreatedAt: "created_at",
}
View Source
var UserModel = model.Definition{
	Name: "user",
	Fields: model.Fields{
		{Name: "id", Type: model.Text(), DB: &model.FieldDB{PK: true}},
		{Name: "email", Type: input.Email(), DB: &model.FieldDB{Unique: true}},
		{Name: "name", Type: input.Text()},
		{Name: "phone", Type: input.Phone()},
		{Name: "status", Type: model.Text()},
		{Name: "created_at", Type: model.Int()},
		{Name: "roles", Type: model.StructSlice(&RoleModel), Exclude: true},
		{Name: "permissions", Type: model.StructSlice(&PermissionModel), Exclude: true},
	},
}
View Source
var UserRoleModel = model.Definition{
	Name: "user_role",
	Fields: model.Fields{
		{Name: "user_id", Type: model.Text(), DB: &model.FieldDB{PK: true, RefColumn: "id"}, Ref: &UserModel},
		{Name: "role_id", Type: model.Text(), DB: &model.FieldDB{PK: true, RefColumn: "id"}, Ref: &RoleModel},
	},
}
View Source
var UserRole_ = struct {
	UserId string
	RoleId string
}{
	UserId: "user_id",
	RoleId: "role_id",
}
View Source
var User_ = struct {
	Id          string
	Email       string
	Name        string
	Phone       string
	Status      string
	CreatedAt   string
	Roles       string
	Permissions string
}{
	Id:          "id",
	Email:       "email",
	Name:        "name",
	Phone:       "phone",
	Status:      "status",
	CreatedAt:   "created_at",
	Roles:       "roles",
	Permissions: "permissions",
}

Functions

func NewView added in v0.1.0

func NewView(caller router.Caller) view.Presenter

NewView builds the user-administration Presenter — the tech-agnostic engine a renderer (crudview, or any other) wraps. The app decides which renderer draws it.

Types

type AuthMode added in v0.0.17

type AuthMode uint8

AuthMode selects the session strategy.

const (
	// AuthModeCookie stores a session ID in an HttpOnly cookie.
	// Stateful: requires user_sessions table. Supports immediate revocation.
	AuthModeCookie AuthMode = iota // default

	// AuthModeJWT stores a signed JWT in an HttpOnly cookie.
	// Stateless: no DB lookup per request. No immediate revocation.
	// Ideal for SPA/PWA and multi-server deployments.
	AuthModeJWT

	// AuthModeBearer reads a signed JWT from the "Authorization: Bearer <token>" header.
	// Stateless: for API clients (MCP servers, IDEs, LLMs) that cannot use cookies.
	// Requires JWTSecret.
	AuthModeBearer
)

type Authenticator added in v0.1.0

type Authenticator interface {
	Name() string
	Mount(r router.Router, module any)
}

type Config added in v0.0.2

type Config struct {
	AuthMode AuthMode // default: AuthModeCookie

	// Shared by all modes
	CookieName string // default: "session"
	TokenTTL   int    // default: 86400 (seconds). Session TTL in cookie mode, JWT expiry in JWT mode.

	// Required when AuthMode == AuthModeJWT or AuthMode == AuthModeBearer.
	// Also required to call GenerateAPIToken regardless of AuthMode.
	JWTSecret []byte

	TrustProxy bool

	// Injected authenticators. The consumer can select 1 or N supported authentication modes.
	Authenticators []Authenticator

	// IDs mints primary keys for every record this module creates (users, sessions,
	// oauth states, identities, LAN ips). REQUIRED: authority.New fails if nil —
	// an auth module must never silently pick its own generator.
	IDs model.IDGenerator

	// Events receives security events (user.TopicSecurity). Optional: nil = events
	// are dropped (fire-and-forget contract), never an error.
	Events events.Publisher

	// OnPasswordValidate is called by SetPassword before hashing.
	// Return a non-nil error to reject the password.
	// If nil, only the built-in len >= 8 check applies.
	OnPasswordValidate func(password string) error

	// AfterLoginPath is the path to redirect to after successful login.
	// Default: PathAfterLogin ("/")
	AfterLoginPath string

	// RateLimit is called by endpoints before processing a request.
	// Return a non-nil error to reject the request (429 Too Many Requests).
	// remoteAddr is the client's IP address.
	RateLimit func(remoteAddr string) error
}

type Identity added in v0.0.2

type Identity struct {
	Id         string
	UserId     string
	Provider   string
	ProviderId string
	Email      string
	CreatedAt  int64
}

func ReadOneIdentity added in v0.0.6

func ReadOneIdentity(qb *orm.QB, model *Identity) (*Identity, error)

func (*Identity) DecodeFields added in v0.0.29

func (m *Identity) DecodeFields(r model.FieldReader)

func (*Identity) EncodeFields added in v0.0.29

func (m *Identity) EncodeFields(w model.FieldWriter)

func (*Identity) IsNil added in v0.0.29

func (m *Identity) IsNil() bool

func (*Identity) ModelName added in v0.0.29

func (m *Identity) ModelName() string

func (*Identity) Pointers added in v0.0.6

func (m *Identity) Pointers() []any

func (*Identity) Schema added in v0.0.6

func (m *Identity) Schema() []model.Field

func (*Identity) SchemaExt added in v0.0.30

func (m *Identity) SchemaExt() []model.FieldExt

func (*Identity) Validate added in v0.0.32

func (m *Identity) Validate(action byte) error

type IdentityList added in v0.0.29

type IdentityList []*Identity

func ReadAllIdentity added in v0.0.6

func ReadAllIdentity(qb *orm.QB) (IdentityList, error)

func (*IdentityList) Append added in v0.0.29

func (s *IdentityList) Append() model.Fielder

func (*IdentityList) At added in v0.0.29

func (s *IdentityList) At(i int) model.Fielder

func (*IdentityList) DecodeFields added in v0.0.29

func (s *IdentityList) DecodeFields(_ model.FieldReader)

func (*IdentityList) EncodeFields added in v0.0.29

func (s *IdentityList) EncodeFields(_ model.FieldWriter)

func (*IdentityList) IsNil added in v0.0.29

func (s *IdentityList) IsNil() bool

func (*IdentityList) Len added in v0.0.29

func (s *IdentityList) Len() int

func (*IdentityList) Pointers added in v0.0.29

func (s *IdentityList) Pointers() []any

func (*IdentityList) Schema added in v0.0.29

func (s *IdentityList) Schema() []model.Field

type LANIP added in v0.0.2

type LANIP struct {
	Id        string
	UserId    string
	Ip        string
	Label     string
	CreatedAt int64
}

func ReadOneLANIP added in v0.0.6

func ReadOneLANIP(qb *orm.QB, model *LANIP) (*LANIP, error)

func (*LANIP) DecodeFields added in v0.0.29

func (m *LANIP) DecodeFields(r model.FieldReader)

func (*LANIP) EncodeFields added in v0.0.29

func (m *LANIP) EncodeFields(w model.FieldWriter)

func (*LANIP) IsNil added in v0.0.29

func (m *LANIP) IsNil() bool

func (*LANIP) ModelName added in v0.0.29

func (m *LANIP) ModelName() string

func (*LANIP) Pointers added in v0.0.6

func (m *LANIP) Pointers() []any

func (*LANIP) Schema added in v0.0.6

func (m *LANIP) Schema() []model.Field

func (*LANIP) SchemaExt added in v0.0.30

func (m *LANIP) SchemaExt() []model.FieldExt

func (*LANIP) Validate added in v0.0.32

func (m *LANIP) Validate(action byte) error

type LANIPList added in v0.0.29

type LANIPList []*LANIP

func ReadAllLANIP added in v0.0.6

func ReadAllLANIP(qb *orm.QB) (LANIPList, error)

func (*LANIPList) Append added in v0.0.29

func (s *LANIPList) Append() model.Fielder

func (*LANIPList) At added in v0.0.29

func (s *LANIPList) At(i int) model.Fielder

func (*LANIPList) DecodeFields added in v0.0.29

func (s *LANIPList) DecodeFields(_ model.FieldReader)

func (*LANIPList) EncodeFields added in v0.0.29

func (s *LANIPList) EncodeFields(_ model.FieldWriter)

func (*LANIPList) IsNil added in v0.0.29

func (s *LANIPList) IsNil() bool

func (*LANIPList) Len added in v0.0.29

func (s *LANIPList) Len() int

func (*LANIPList) Pointers added in v0.0.29

func (s *LANIPList) Pointers() []any

func (*LANIPList) Schema added in v0.0.29

func (s *LANIPList) Schema() []model.Field

type LoginData added in v0.0.2

type LoginData struct {
	Email    string
	Password string
}

func (*LoginData) DecodeFields added in v0.0.29

func (m *LoginData) DecodeFields(r model.FieldReader)

func (*LoginData) EncodeFields added in v0.0.29

func (m *LoginData) EncodeFields(w model.FieldWriter)

func (*LoginData) IsNil added in v0.0.29

func (m *LoginData) IsNil() bool

func (*LoginData) ModelName added in v0.0.29

func (m *LoginData) ModelName() string

func (*LoginData) Pointers added in v0.0.28

func (m *LoginData) Pointers() []any

func (*LoginData) Schema added in v0.0.28

func (m *LoginData) Schema() []model.Field

func (*LoginData) Validate added in v0.0.32

func (m *LoginData) Validate(action byte) error

type LoginDataList added in v0.0.29

type LoginDataList []*LoginData

func (*LoginDataList) Append added in v0.0.29

func (s *LoginDataList) Append() model.Fielder

func (*LoginDataList) At added in v0.0.29

func (s *LoginDataList) At(i int) model.Fielder

func (*LoginDataList) DecodeFields added in v0.0.29

func (s *LoginDataList) DecodeFields(_ model.FieldReader)

func (*LoginDataList) EncodeFields added in v0.0.29

func (s *LoginDataList) EncodeFields(_ model.FieldWriter)

func (*LoginDataList) IsNil added in v0.0.29

func (s *LoginDataList) IsNil() bool

func (*LoginDataList) Len added in v0.0.29

func (s *LoginDataList) Len() int

func (*LoginDataList) Pointers added in v0.0.29

func (s *LoginDataList) Pointers() []any

func (*LoginDataList) Schema added in v0.0.29

func (s *LoginDataList) Schema() []model.Field

type ModuleContext added in v0.1.0

type ModuleContext interface {
	Config() Config
	DB() *orm.DB
	IDs() model.IDGenerator
	Notify(e SecurityEvent)
	IssueToken(userID string, ttl int) (string, error)
	CreateSession(userID, ip, userAgent string) (Session, error)
	DeleteSession(id string) error
	GetSession(id string) (Session, error)
	Login(email, password string) (User, error)
	ExtractClientIP(ctx router.Context) string
	RegisterProvider(p OAuthProvider)
	BeginOAuth(providerName string) (string, error)
	CompleteOAuth(providerName string, ctx router.Context, ip, ua string) (User, bool, error)
}

type OAuthConfig added in v0.0.34

type OAuthConfig struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
	AuthURL      string // provider's authorization endpoint
	TokenURL     string // provider's token endpoint
}

OAuthConfig is the provider's registration: what the app declares in the provider console.

type OAuthProvider added in v0.0.2

type OAuthProvider interface {
	Name() string
	AuthCodeURL(state string) string
	ExchangeCode(code string) (OAuthToken, error)
	GetUserInfo(token OAuthToken) (OAuthUserInfo, error)
}

type OAuthState added in v0.0.6

type OAuthState struct {
	State     string
	Provider  string
	ExpiresAt int64
	CreatedAt int64
}

func ReadOneOAuthState added in v0.0.6

func ReadOneOAuthState(qb *orm.QB, model *OAuthState) (*OAuthState, error)

func (*OAuthState) DecodeFields added in v0.0.29

func (m *OAuthState) DecodeFields(r model.FieldReader)

func (*OAuthState) EncodeFields added in v0.0.29

func (m *OAuthState) EncodeFields(w model.FieldWriter)

func (*OAuthState) IsNil added in v0.0.29

func (m *OAuthState) IsNil() bool

func (*OAuthState) ModelName added in v0.0.29

func (m *OAuthState) ModelName() string

func (*OAuthState) Pointers added in v0.0.6

func (m *OAuthState) Pointers() []any

func (*OAuthState) Schema added in v0.0.6

func (m *OAuthState) Schema() []model.Field

func (*OAuthState) Validate added in v0.0.32

func (m *OAuthState) Validate(action byte) error

type OAuthStateList added in v0.0.29

type OAuthStateList []*OAuthState

func ReadAllOAuthState added in v0.0.6

func ReadAllOAuthState(qb *orm.QB) (OAuthStateList, error)

func (*OAuthStateList) Append added in v0.0.29

func (s *OAuthStateList) Append() model.Fielder

func (*OAuthStateList) At added in v0.0.29

func (s *OAuthStateList) At(i int) model.Fielder

func (*OAuthStateList) DecodeFields added in v0.0.29

func (s *OAuthStateList) DecodeFields(_ model.FieldReader)

func (*OAuthStateList) EncodeFields added in v0.0.29

func (s *OAuthStateList) EncodeFields(_ model.FieldWriter)

func (*OAuthStateList) IsNil added in v0.0.29

func (s *OAuthStateList) IsNil() bool

func (*OAuthStateList) Len added in v0.0.29

func (s *OAuthStateList) Len() int

func (*OAuthStateList) Pointers added in v0.0.29

func (s *OAuthStateList) Pointers() []any

func (*OAuthStateList) Schema added in v0.0.29

func (s *OAuthStateList) Schema() []model.Field

type OAuthToken added in v0.0.34

type OAuthToken struct {
	AccessToken string
	TokenType   string
	ExpiresIn   int
}

OAuthToken is what a provider returns when it exchanges the code. It replaces oauth2.Token: that type dragged net/http in, and net/http does not exist under TinyGo — which put this whole module out of the edge for one function call.

func (*OAuthToken) DecodeFields added in v0.0.34

func (t *OAuthToken) DecodeFields(r model.FieldReader)

func (OAuthToken) IsNil added in v0.0.34

func (t OAuthToken) IsNil() bool

type OAuthUserInfo added in v0.0.2

type OAuthUserInfo struct {
	ID    string
	Email string
	Name  string
}

type PasswordData added in v0.0.2

type PasswordData struct {
	Current string
	New     string
	Confirm string
}

func (*PasswordData) DecodeFields added in v0.0.29

func (m *PasswordData) DecodeFields(r model.FieldReader)

func (*PasswordData) EncodeFields added in v0.0.29

func (m *PasswordData) EncodeFields(w model.FieldWriter)

func (*PasswordData) IsNil added in v0.0.29

func (m *PasswordData) IsNil() bool

func (*PasswordData) ModelName added in v0.0.29

func (m *PasswordData) ModelName() string

func (*PasswordData) Pointers added in v0.0.28

func (m *PasswordData) Pointers() []any

func (*PasswordData) Schema added in v0.0.28

func (m *PasswordData) Schema() []model.Field

func (*PasswordData) Validate added in v0.0.32

func (m *PasswordData) Validate(action byte) error

type PasswordDataList added in v0.0.29

type PasswordDataList []*PasswordData

func (*PasswordDataList) Append added in v0.0.29

func (s *PasswordDataList) Append() model.Fielder

func (*PasswordDataList) At added in v0.0.29

func (s *PasswordDataList) At(i int) model.Fielder

func (*PasswordDataList) DecodeFields added in v0.0.29

func (s *PasswordDataList) DecodeFields(_ model.FieldReader)

func (*PasswordDataList) EncodeFields added in v0.0.29

func (s *PasswordDataList) EncodeFields(_ model.FieldWriter)

func (*PasswordDataList) IsNil added in v0.0.29

func (s *PasswordDataList) IsNil() bool

func (*PasswordDataList) Len added in v0.0.29

func (s *PasswordDataList) Len() int

func (*PasswordDataList) Pointers added in v0.0.29

func (s *PasswordDataList) Pointers() []any

func (*PasswordDataList) Schema added in v0.0.29

func (s *PasswordDataList) Schema() []model.Field

type Permission added in v0.0.6

type Permission struct {
	Id       string
	Name     string
	Resource string
	Action   string
}

func ReadOnePermission added in v0.0.6

func ReadOnePermission(qb *orm.QB, model *Permission) (*Permission, error)

func (*Permission) DecodeFields added in v0.0.29

func (m *Permission) DecodeFields(r model.FieldReader)

func (*Permission) EncodeFields added in v0.0.29

func (m *Permission) EncodeFields(w model.FieldWriter)

func (*Permission) IsNil added in v0.0.29

func (m *Permission) IsNil() bool

func (*Permission) ModelName added in v0.0.29

func (m *Permission) ModelName() string

func (*Permission) Pointers added in v0.0.6

func (m *Permission) Pointers() []any

func (*Permission) Schema added in v0.0.6

func (m *Permission) Schema() []model.Field

func (*Permission) Validate added in v0.0.32

func (m *Permission) Validate(action byte) error

type PermissionList added in v0.0.29

type PermissionList []*Permission

func ReadAllPermission added in v0.0.6

func ReadAllPermission(qb *orm.QB) (PermissionList, error)

func (*PermissionList) Append added in v0.0.29

func (s *PermissionList) Append() model.Fielder

func (*PermissionList) At added in v0.0.29

func (s *PermissionList) At(i int) model.Fielder

func (*PermissionList) DecodeFields added in v0.0.29

func (s *PermissionList) DecodeFields(_ model.FieldReader)

func (*PermissionList) EncodeFields added in v0.0.29

func (s *PermissionList) EncodeFields(_ model.FieldWriter)

func (*PermissionList) IsNil added in v0.0.29

func (s *PermissionList) IsNil() bool

func (*PermissionList) Len added in v0.0.29

func (s *PermissionList) Len() int

func (*PermissionList) Pointers added in v0.0.29

func (s *PermissionList) Pointers() []any

func (*PermissionList) Schema added in v0.0.29

func (s *PermissionList) Schema() []model.Field

type ProfileDTO added in v0.0.30

type ProfileDTO struct {
	Id          string
	Name        string
	Email       string
	Avatar      string
	Roles       []string
	Permissions []string // "resource:actions" pairs, e.g. "service_catalog:rc"
	Locale      string
}

ProfileDTO is a safe subset of User data for public/API consumption.

func (*ProfileDTO) DecodeFields added in v0.0.30

func (p *ProfileDTO) DecodeFields(r model.FieldReader)

func (ProfileDTO) EncodeFields added in v0.0.30

func (p ProfileDTO) EncodeFields(w model.FieldWriter)

func (ProfileDTO) IsNil added in v0.0.30

func (p ProfileDTO) IsNil() bool

type ProfileData added in v0.0.2

type ProfileData struct {
	Name  string
	Phone string
}

func (*ProfileData) DecodeFields added in v0.0.29

func (m *ProfileData) DecodeFields(r model.FieldReader)

func (*ProfileData) EncodeFields added in v0.0.29

func (m *ProfileData) EncodeFields(w model.FieldWriter)

func (*ProfileData) IsNil added in v0.0.29

func (m *ProfileData) IsNil() bool

func (*ProfileData) ModelName added in v0.0.29

func (m *ProfileData) ModelName() string

func (*ProfileData) Pointers added in v0.0.28

func (m *ProfileData) Pointers() []any

func (*ProfileData) Schema added in v0.0.28

func (m *ProfileData) Schema() []model.Field

func (*ProfileData) Validate added in v0.0.32

func (m *ProfileData) Validate(action byte) error

type ProfileDataList added in v0.0.29

type ProfileDataList []*ProfileData

func (*ProfileDataList) Append added in v0.0.29

func (s *ProfileDataList) Append() model.Fielder

func (*ProfileDataList) At added in v0.0.29

func (s *ProfileDataList) At(i int) model.Fielder

func (*ProfileDataList) DecodeFields added in v0.0.29

func (s *ProfileDataList) DecodeFields(_ model.FieldReader)

func (*ProfileDataList) EncodeFields added in v0.0.29

func (s *ProfileDataList) EncodeFields(_ model.FieldWriter)

func (*ProfileDataList) IsNil added in v0.0.29

func (s *ProfileDataList) IsNil() bool

func (*ProfileDataList) Len added in v0.0.29

func (s *ProfileDataList) Len() int

func (*ProfileDataList) Pointers added in v0.0.29

func (s *ProfileDataList) Pointers() []any

func (*ProfileDataList) Schema added in v0.0.29

func (s *ProfileDataList) Schema() []model.Field

type RegisterData added in v0.0.2

type RegisterData struct {
	Name     string
	Email    string
	Password string
	Phone    string
}

func (*RegisterData) DecodeFields added in v0.0.29

func (m *RegisterData) DecodeFields(r model.FieldReader)

func (*RegisterData) EncodeFields added in v0.0.29

func (m *RegisterData) EncodeFields(w model.FieldWriter)

func (*RegisterData) IsNil added in v0.0.29

func (m *RegisterData) IsNil() bool

func (*RegisterData) ModelName added in v0.0.29

func (m *RegisterData) ModelName() string

func (*RegisterData) Pointers added in v0.0.28

func (m *RegisterData) Pointers() []any

func (*RegisterData) Schema added in v0.0.28

func (m *RegisterData) Schema() []model.Field

func (*RegisterData) Validate added in v0.0.32

func (m *RegisterData) Validate(action byte) error

type RegisterDataList added in v0.0.29

type RegisterDataList []*RegisterData

func (*RegisterDataList) Append added in v0.0.29

func (s *RegisterDataList) Append() model.Fielder

func (*RegisterDataList) At added in v0.0.29

func (s *RegisterDataList) At(i int) model.Fielder

func (*RegisterDataList) DecodeFields added in v0.0.29

func (s *RegisterDataList) DecodeFields(_ model.FieldReader)

func (*RegisterDataList) EncodeFields added in v0.0.29

func (s *RegisterDataList) EncodeFields(_ model.FieldWriter)

func (*RegisterDataList) IsNil added in v0.0.29

func (s *RegisterDataList) IsNil() bool

func (*RegisterDataList) Len added in v0.0.29

func (s *RegisterDataList) Len() int

func (*RegisterDataList) Pointers added in v0.0.29

func (s *RegisterDataList) Pointers() []any

func (*RegisterDataList) Schema added in v0.0.29

func (s *RegisterDataList) Schema() []model.Field

type Role added in v0.0.6

type Role struct {
	Id          string
	Code        string
	Name        string
	Description string
}

func ReadOneRole added in v0.0.6

func ReadOneRole(qb *orm.QB, model *Role) (*Role, error)

func (*Role) DecodeFields added in v0.0.29

func (m *Role) DecodeFields(r model.FieldReader)

func (*Role) EncodeFields added in v0.0.29

func (m *Role) EncodeFields(w model.FieldWriter)

func (*Role) IsNil added in v0.0.29

func (m *Role) IsNil() bool

func (*Role) ModelName added in v0.0.29

func (m *Role) ModelName() string

func (*Role) Pointers added in v0.0.6

func (m *Role) Pointers() []any

func (*Role) Schema added in v0.0.6

func (m *Role) Schema() []model.Field

func (*Role) Validate added in v0.0.32

func (m *Role) Validate(action byte) error

type RoleList added in v0.0.29

type RoleList []*Role

func ReadAllRole added in v0.0.6

func ReadAllRole(qb *orm.QB) (RoleList, error)

func (*RoleList) Append added in v0.0.29

func (s *RoleList) Append() model.Fielder

func (*RoleList) At added in v0.0.29

func (s *RoleList) At(i int) model.Fielder

func (*RoleList) DecodeFields added in v0.0.29

func (s *RoleList) DecodeFields(_ model.FieldReader)

func (*RoleList) EncodeFields added in v0.0.29

func (s *RoleList) EncodeFields(_ model.FieldWriter)

func (*RoleList) IsNil added in v0.0.29

func (s *RoleList) IsNil() bool

func (*RoleList) Len added in v0.0.29

func (s *RoleList) Len() int

func (*RoleList) Pointers added in v0.0.29

func (s *RoleList) Pointers() []any

func (*RoleList) Schema added in v0.0.29

func (s *RoleList) Schema() []model.Field

type RolePermission added in v0.0.6

type RolePermission struct {
	RoleId       string
	PermissionId string
}

func ReadOneRolePermission added in v0.0.6

func ReadOneRolePermission(qb *orm.QB, model *RolePermission) (*RolePermission, error)

func (*RolePermission) DecodeFields added in v0.0.29

func (m *RolePermission) DecodeFields(r model.FieldReader)

func (*RolePermission) EncodeFields added in v0.0.29

func (m *RolePermission) EncodeFields(w model.FieldWriter)

func (*RolePermission) IsNil added in v0.0.29

func (m *RolePermission) IsNil() bool

func (*RolePermission) ModelName added in v0.0.29

func (m *RolePermission) ModelName() string

func (*RolePermission) Pointers added in v0.0.6

func (m *RolePermission) Pointers() []any

func (*RolePermission) Schema added in v0.0.6

func (m *RolePermission) Schema() []model.Field

func (*RolePermission) SchemaExt added in v0.0.30

func (m *RolePermission) SchemaExt() []model.FieldExt

func (*RolePermission) Validate added in v0.0.32

func (m *RolePermission) Validate(action byte) error

type RolePermissionList added in v0.0.29

type RolePermissionList []*RolePermission

func ReadAllRolePermission added in v0.0.6

func ReadAllRolePermission(qb *orm.QB) (RolePermissionList, error)

func (*RolePermissionList) Append added in v0.0.29

func (s *RolePermissionList) Append() model.Fielder

func (*RolePermissionList) At added in v0.0.29

func (*RolePermissionList) DecodeFields added in v0.0.29

func (s *RolePermissionList) DecodeFields(_ model.FieldReader)

func (*RolePermissionList) EncodeFields added in v0.0.29

func (s *RolePermissionList) EncodeFields(_ model.FieldWriter)

func (*RolePermissionList) IsNil added in v0.0.29

func (s *RolePermissionList) IsNil() bool

func (*RolePermissionList) Len added in v0.0.29

func (s *RolePermissionList) Len() int

func (*RolePermissionList) Pointers added in v0.0.29

func (s *RolePermissionList) Pointers() []any

func (*RolePermissionList) Schema added in v0.0.29

func (s *RolePermissionList) Schema() []model.Field

type SecurityEvent added in v0.0.22

type SecurityEvent struct {
	Type      SecurityEventType
	IP        string // client IP, empty if not available
	UserID    string // empty if user not yet identified
	Provider  string // OAuth provider name, for OAuth events
	Resource  string // RBAC resource, for EventAccessDenied
	Timestamp int64  // time.Now().Unix()
}

func (*SecurityEvent) EncodeFields added in v0.1.0

func (e *SecurityEvent) EncodeFields(w model.FieldWriter)

func (*SecurityEvent) IsNil added in v0.1.0

func (e *SecurityEvent) IsNil() bool

type SecurityEventType added in v0.0.22

type SecurityEventType uint8
const (
	EventJWTTampered        SecurityEventType = iota // validateJWT: jwt.Forged (never jwt.Expired)
	EventOAuthReplay                                 // consumeState: state already consumed (2nd use)
	EventOAuthExpiredState                           // consumeState: state found but past ExpiresAt
	EventOAuthCrossProvider                          // consumeState: provider mismatch (state preserved)
	EventIPMismatch                                  // LoginLAN: IP not registered
	EventNonActiveAccess                             // Login/LoginLAN: status != "active"
	EventUnauthorizedAccess                          // validateSession: cookie present but session invalid
	EventAccessDenied                                // AccessCheck: RBAC denied with valid session
	EventPermissionCorrupt                           // HasPermission: permissions.action is not a CRUD string
	EventRateLimited                                 // POST /login: Config.RateLimit rejected the attempt before bcrypt
)

type Session added in v0.0.2

type Session struct {
	Id        string
	UserId    string
	ExpiresAt int64
	Ip        string
	UserAgent string
	CreatedAt int64
}

func ReadOneSession added in v0.0.6

func ReadOneSession(qb *orm.QB, model *Session) (*Session, error)

func (*Session) DecodeFields added in v0.0.29

func (m *Session) DecodeFields(r model.FieldReader)

func (*Session) EncodeFields added in v0.0.29

func (m *Session) EncodeFields(w model.FieldWriter)

func (*Session) IsNil added in v0.0.29

func (m *Session) IsNil() bool

func (*Session) ModelName added in v0.0.29

func (m *Session) ModelName() string

func (*Session) Pointers added in v0.0.6

func (m *Session) Pointers() []any

func (*Session) Schema added in v0.0.6

func (m *Session) Schema() []model.Field

func (*Session) SchemaExt added in v0.0.30

func (m *Session) SchemaExt() []model.FieldExt

func (*Session) Validate added in v0.0.32

func (m *Session) Validate(action byte) error

type SessionList added in v0.0.29

type SessionList []*Session

func ReadAllSession added in v0.0.6

func ReadAllSession(qb *orm.QB) (SessionList, error)

func (*SessionList) Append added in v0.0.29

func (s *SessionList) Append() model.Fielder

func (*SessionList) At added in v0.0.29

func (s *SessionList) At(i int) model.Fielder

func (*SessionList) DecodeFields added in v0.0.29

func (s *SessionList) DecodeFields(_ model.FieldReader)

func (*SessionList) EncodeFields added in v0.0.29

func (s *SessionList) EncodeFields(_ model.FieldWriter)

func (*SessionList) IsNil added in v0.0.29

func (s *SessionList) IsNil() bool

func (*SessionList) Len added in v0.0.29

func (s *SessionList) Len() int

func (*SessionList) Pointers added in v0.0.29

func (s *SessionList) Pointers() []any

func (*SessionList) Schema added in v0.0.29

func (s *SessionList) Schema() []model.Field

type User

type User struct {
	Id          string
	Email       string
	Name        string
	Phone       string
	Status      string
	CreatedAt   int64
	Roles       []Role
	Permissions []Permission
}

func ReadOneUser added in v0.0.6

func ReadOneUser(qb *orm.QB, model *User) (*User, error)

func (*User) DecodeFields added in v0.0.29

func (m *User) DecodeFields(r model.FieldReader)

func (*User) EncodeFields added in v0.0.29

func (m *User) EncodeFields(w model.FieldWriter)

func (*User) IsNil added in v0.0.29

func (m *User) IsNil() bool

func (*User) Item added in v0.1.0

func (m *User) Item() view.Item

Item projects a User as a list row (view.Itemizer) — the ONLY view-specific code this module writes on its model.

func (*User) ModelName added in v0.0.29

func (m *User) ModelName() string

func (*User) Pointers added in v0.0.6

func (m *User) Pointers() []any

func (*User) Schema added in v0.0.6

func (m *User) Schema() []model.Field

func (*User) Validate added in v0.0.32

func (m *User) Validate(action byte) error

type UserList added in v0.0.29

type UserList []*User

func ReadAllUser added in v0.0.6

func ReadAllUser(qb *orm.QB) (UserList, error)

func (*UserList) Append added in v0.0.29

func (s *UserList) Append() model.Fielder

func (*UserList) At added in v0.0.29

func (s *UserList) At(i int) model.Fielder

func (*UserList) DecodeFields added in v0.0.29

func (s *UserList) DecodeFields(_ model.FieldReader)

func (*UserList) EncodeFields added in v0.0.29

func (s *UserList) EncodeFields(_ model.FieldWriter)

func (*UserList) IsNil added in v0.0.29

func (s *UserList) IsNil() bool

func (*UserList) Len added in v0.0.29

func (s *UserList) Len() int

func (*UserList) Pointers added in v0.0.29

func (s *UserList) Pointers() []any

func (*UserList) Schema added in v0.0.29

func (s *UserList) Schema() []model.Field

type UserRole added in v0.0.6

type UserRole struct {
	UserId string
	RoleId string
}

func ReadOneUserRole added in v0.0.6

func ReadOneUserRole(qb *orm.QB, model *UserRole) (*UserRole, error)

func (*UserRole) DecodeFields added in v0.0.29

func (m *UserRole) DecodeFields(r model.FieldReader)

func (*UserRole) EncodeFields added in v0.0.29

func (m *UserRole) EncodeFields(w model.FieldWriter)

func (*UserRole) IsNil added in v0.0.29

func (m *UserRole) IsNil() bool

func (*UserRole) ModelName added in v0.0.29

func (m *UserRole) ModelName() string

func (*UserRole) Pointers added in v0.0.6

func (m *UserRole) Pointers() []any

func (*UserRole) Schema added in v0.0.6

func (m *UserRole) Schema() []model.Field

func (*UserRole) SchemaExt added in v0.0.30

func (m *UserRole) SchemaExt() []model.FieldExt

func (*UserRole) Validate added in v0.0.32

func (m *UserRole) Validate(action byte) error

type UserRoleList added in v0.0.29

type UserRoleList []*UserRole

func ReadAllUserRole added in v0.0.6

func ReadAllUserRole(qb *orm.QB) (UserRoleList, error)

func (*UserRoleList) Append added in v0.0.29

func (s *UserRoleList) Append() model.Fielder

func (*UserRoleList) At added in v0.0.29

func (s *UserRoleList) At(i int) model.Fielder

func (*UserRoleList) DecodeFields added in v0.0.29

func (s *UserRoleList) DecodeFields(_ model.FieldReader)

func (*UserRoleList) EncodeFields added in v0.0.29

func (s *UserRoleList) EncodeFields(_ model.FieldWriter)

func (*UserRoleList) IsNil added in v0.0.29

func (s *UserRoleList) IsNil() bool

func (*UserRoleList) Len added in v0.0.29

func (s *UserRoleList) Len() int

func (*UserRoleList) Pointers added in v0.0.29

func (s *UserRoleList) Pointers() []any

func (*UserRoleList) Schema added in v0.0.29

func (s *UserRoleList) Schema() []model.Field

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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