users

package
v0.0.0-...-df9fb1a Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionContextKey  ContextKey = "session"
	ErrLoginFailed                = "login failed"
	ErrMustUsePost                = "must use POST"
	ErrInvalidToken               = "token invalid"
	ErrInvalidAudience            = "audience invalid"
)

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrNoDBConnection = errors.New("no database connection")
	ErrNotFound       = errors.New("wrong username or password")
	Config            = Configuration{}
)

Functions

func AddItemForUser

func AddItemForUser(username string, itemId int) error

func AddKeywordForUser

func AddKeywordForUser(keyword Keyword, username string) error

func CreateUser

func CreateUser(username string, password string) error

func DeleteCookie

func DeleteCookie(next http.HandlerFunc) http.HandlerFunc

func DeleteItemForUser

func DeleteItemForUser(username string, itemId int) error

func DeleteKeywordForUser

func DeleteKeywordForUser(keywordID uint, username string) error

func LoginMiddleware

func LoginMiddleware(loginFailedRedirect string, next http.HandlerFunc) http.HandlerFunc

func SavedItemsForUser

func SavedItemsForUser(username string) ([]feeds.Item, error)

func SessionMiddleware

func SessionMiddleware(noSessionRedirect string, next http.HandlerFunc) http.HandlerFunc

looks for a cookie that identifies the user; if not found, redirects to url provided as noSessionRedirect

func VerifyUser

func VerifyUser(username string, password string) error

returns NIL on success

Types

type Configuration

type Configuration struct {
	DB     *gorm.DB
	Secret []byte
}

func (*Configuration) OpenDatabase

func (c *Configuration) OpenDatabase(path string) error

type ContextKey

type ContextKey string

type CustomClaims

type CustomClaims struct {
	jwt.RegisteredClaims
	Admin bool `json:"adm"`
}

type Keyword

type Keyword struct {
	ID         uint `gorm:"primaryKey"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Mode       KeywordMode // the mode (highlight or suppress)
	Text       string      // the keyword that will trigger
	Annotation string      // an optional note explaining this keyword
	UserID     uint        // reference back to user
}

type KeywordList

type KeywordList []Keyword

func KeywordsForUser

func KeywordsForUser(name string) (KeywordList, error)

func (KeywordList) Match

func (kl KeywordList) Match(search string) (KeywordMode, string)

Compares a the search string provided to the keyword list and returns a Mode (highlight/suppress/do nothing)

type KeywordMode

type KeywordMode string
const (
	HighlightMode KeywordMode = "KeywordHighlight"
	SuppressMode  KeywordMode = "KeywordSuppress"
	DoNothingMode KeywordMode = "KeywordIgnore"
)

type Session

type Session struct {
	Id    string
	User  string
	Admin bool
}

type User

type User struct {
	gorm.Model
	UserName   string
	Password   string
	Keywords   []Keyword
	SavedItems []feeds.Item `gorm:"many2many:user_saved_items"`
}

func UserByName

func UserByName(name string) (User, error)

Jump to

Keyboard shortcuts

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