users

package module
v0.0.0-...-9deee3c Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 6 Imported by: 2

README

#+TITLE: Users
#+AUTHOR: Christopher James Hayward
#+EMAIL: chris@chrishayward.xyz

User accounts and sessions for simple peons.

* Introduction

This is a simple library for creating a service capable of storing a dataset of Users, and providing methods for them to access a service through their configured accounts. The core library does not depend on any external projects, and is based entirely off the Go standard library.

* Examples

+ [[https://git.chrishayward.xyz/chris/users-http][HTTP Implementation]]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailValidator

type EmailValidator interface {
	Validate(string) error
}

func NewDefaultEmailValidator

func NewDefaultEmailValidator() EmailValidator

type LoginHandler

type LoginHandler interface {
	Handle(*LoginRequest) (*LoginResponse, error)
}

func NewLoginHandler

func NewLoginHandler(userDB UserDB, emailValidator EmailValidator, passwordEncoder PasswordEncoder, tokenStore TokenStore) LoginHandler

type LoginRequest

type LoginRequest struct {
	Email    string
	Password string
}

type LoginResponse

type LoginResponse struct {
	Token string
}

type LogoutHandler

type LogoutHandler interface {
	Handle(*LogoutRequest) (*LogoutResponse, error)
}

func NewLogoutHandler

func NewLogoutHandler(tokenStore TokenStore) LogoutHandler

type LogoutRequest

type LogoutRequest struct {
	Token string
}

type LogoutResponse

type LogoutResponse struct{}

type PasswordEncoder

type PasswordEncoder interface {
	Encode(string) ([]byte, error)
	Compare(string, []byte) error
}

func NewUnsafePasswordEncoder

func NewUnsafePasswordEncoder() PasswordEncoder

type RegistrationHandler

type RegistrationHandler interface {
	Handle(*RegistrationRequest) (*RegistrationResponse, error)
}

func NewRegistrationHandler

func NewRegistrationHandler(userDB UserDB, emailValidator EmailValidator, passwordEncoder PasswordEncoder) RegistrationHandler

type RegistrationRequest

type RegistrationRequest struct {
	Email    string
	Password string
}

type RegistrationResponse

type RegistrationResponse struct{}

type TokenStore

type TokenStore interface {
	Encode(uint64) (string, error)
	Decode(string) (uint64, error)
	Revoke(string) error
}

func NewInMemoryTokenStore

func NewInMemoryTokenStore(duration time.Duration) TokenStore

type User

type User struct {
	ID       uint64
	Email    string
	Password string
}

type UserDB

type UserDB interface {
	FindByID(uint64) (*User, error)
	FindByEmail(string) (*User, error)
	Save(*User) error
}

func NewInMemoryUserDB

func NewInMemoryUserDB() UserDB

Jump to

Keyboard shortcuts

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