auth

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsernameMaxLength        = 255
	UserProfileNameMaxLength = 255
	UserSearchMaxLength      = 1024
)
View Source
const SVAROG_SESSION = "svarog_session"

Variables

View Source
var (
	ErrUserNotFound            = errors.New("User not found")
	ErrUserExists              = errors.New("User already exists")
	ErrLoginTokenInvalid       = errors.New("Login token not valid")
	ErrPasswordBlank           = errors.New("password must contain at least 8 non-space characters")
	ErrPasswordTooLong         = errors.New("Password must contain between 8 and 72 bytes")
	ErrInvalidPassword         = errors.New("Invalid password")
	ErrProjectSelectionMissing = errors.New("project selection missing")
)

Functions

func IsAdmin

func IsAdmin(ctx context.Context) bool

func ValidateNewPassword

func ValidateNewPassword(password string) error

ValidateNewPassword rejects a password whose meaningful content is shorter than 8 characters. Eight spaces pass a raw length check and can then be used to log in. The stored value is not trimmed: surrounding spaces in an otherwise long password stay significant.

func ValidateUserInput added in v0.0.11

func ValidateUserInput(input UserInput) error

Types

type LoggedInUser

type LoggedInUser struct {
	ID                 string   `json:"id"`
	Username           string   `json:"username"`
	Role               Role     `json:"role"`
	NeedsPasswordReset bool     `json:"needsPasswordReset"`
	ProjectIDs         []string `json:"projectIds,omitempty"`
}

type PageQuery added in v0.0.11

type PageQuery struct {
	// contains filtered or unexported fields
}

PageQuery is constructed by NewPageQuery. Its zero value is the default first page.

func NewPageQuery added in v0.0.11

func NewPageQuery(search string, page, size int64) (PageQuery, error)

func (PageQuery) ClampPage added in v0.0.11

func (q PageQuery) ClampPage(maximum int64) PageQuery

ClampPage moves to an earlier available page without changing the search or size.

func (PageQuery) Page added in v0.0.11

func (q PageQuery) Page() int64

func (PageQuery) Search added in v0.0.11

func (q PageQuery) Search() string

func (PageQuery) Size added in v0.0.11

func (q PageQuery) Size() int64

type PostgresAuthService

type PostgresAuthService struct {
	// contains filtered or unexported fields
}

func NewPostgresAuthService

func NewPostgresAuthService(pool *pgxpool.Pool, sessionStore *PostgresSessionStore) *PostgresAuthService

func (*PostgresAuthService) CreateInitialAdminUser

func (a *PostgresAuthService) CreateInitialAdminUser(ctx context.Context) error

func (*PostgresAuthService) CreateUser added in v0.0.11

func (a *PostgresAuthService) CreateUser(ctx context.Context, input UserInput) (User, string, error)

func (*PostgresAuthService) DeleteUser

func (a *PostgresAuthService) DeleteUser(ctx context.Context, id string) error

func (*PostgresAuthService) GenerateLoginToken

func (a *PostgresAuthService) GenerateLoginToken(ctx context.Context, userID string) (string, error)

func (*PostgresAuthService) GetCurrentUser

func (a *PostgresAuthService) GetCurrentUser(ctx *echo.Context) (LoggedInUser, error)

func (*PostgresAuthService) GetProjectIDsForUser

func (a *PostgresAuthService) GetProjectIDsForUser(ctx context.Context, userID string) ([]string, error)

func (*PostgresAuthService) GetUserByID

func (a *PostgresAuthService) GetUserByID(ctx context.Context, id string) (User, error)

func (*PostgresAuthService) GetUserByUsername

func (a *PostgresAuthService) GetUserByUsername(ctx context.Context, username string) (User, error)

func (*PostgresAuthService) GetUserPage

func (a *PostgresAuthService) GetUserPage(ctx context.Context, query PageQuery) ([]User, int64, error)

func (*PostgresAuthService) Login

func (a *PostgresAuthService) Login(ctx *echo.Context, username, password string) error

func (*PostgresAuthService) LoginWithToken

func (a *PostgresAuthService) LoginWithToken(ctx *echo.Context, token string) error

func (*PostgresAuthService) Logout

func (a *PostgresAuthService) Logout(ctx *echo.Context) error

func (*PostgresAuthService) ResetPassword

func (a *PostgresAuthService) ResetPassword(ctx context.Context, userID string, password string) error

func (*PostgresAuthService) UpdateUser added in v0.0.11

func (a *PostgresAuthService) UpdateUser(ctx context.Context, id uuid.UUID, input UserInput) (User, error)

func (*PostgresAuthService) UserHasAccessToProject

func (a *PostgresAuthService) UserHasAccessToProject(ctx context.Context, userID, projectID string) (bool, error)

type PostgresSessionStore

type PostgresSessionStore struct {
	// contains filtered or unexported fields
}

func NewPostgresSessionStore

func NewPostgresSessionStore(pool *pgxpool.Pool, secretKey []byte) *PostgresSessionStore

func (*PostgresSessionStore) Get

func (*PostgresSessionStore) New

func (*PostgresSessionStore) Save

type Role

type Role string
const (
	ADMIN Role = "admin"
	USER  Role = "user"
)

type User

type User struct {
	ID                 uuid.UUID `json:"id"`
	FirstName          string    `json:"firstName"`
	LastName           string    `json:"lastName"`
	Username           string    `json:"username"`
	Password           string    `json:"-"`
	Role               Role      `json:"role"`
	NeedsPasswordReset bool      `json:"needsPasswordReset"`
	ProjectIDs         []string  `json:"projectIds,omitempty"`
}

type UserContext

type UserContext int
const (
	UserKey UserContext = iota
	IsAdminKey
)

func (UserContext) String

func (c UserContext) String() string

type UserInput added in v0.0.11

type UserInput struct {
	Username, FirstName, LastName string
	Role                          Role
	ProjectIDs                    []uuid.UUID
}

Jump to

Keyboard shortcuts

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