auth

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ErrUserNotFound     = "User not found"
	UserAlreadyExists   = "User already exists"
	LoginTokenNotValid  = "Login token not valid"
	PasswordsDoNotMatch = "Passwords do not match"
	ErrPasswordBlank    = "password must contain at least 8 non-space characters"
)
View Source
const SVAROG_SESSION = "svarog_session"

Variables

This section is empty.

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 ValidateUserForm

func ValidateUserForm(ctx context.Context, form types.CreateUserForm) error

func ValidateUserPage

func ValidateUserPage(ctx context.Context, query types.GetUserPageInput) error

Types

type AuthService

type AuthService interface {
	Login(ctx *echo.Context, username string, password string) error
	LoginWithToken(ctx *echo.Context, token string) error
	Logout(ctx *echo.Context) error
	ResetPassword(ctx context.Context, userId string, form types.ResetPasswordForm) error
	GenerateLoginToken(ctx context.Context, userId string) (string, error)
	DeleteUser(ctx *echo.Context, id string) error
	GetCurrentUser(ctx *echo.Context) (LoggedInUser, error)
	GetUserByID(ctx context.Context, id string) (User, error)
	GetUserByUsername(ctx context.Context, username string) (User, error)
	GetUserPage(ctx context.Context, query types.GetUserPageInput) ([]User, int64, error)
	CreateOrUpdateUser(ctx context.Context, form types.CreateUserForm) (User, error)
	UserHasAccessToProject(ctx context.Context, userId, projectId string) (bool, error)
	GetProjectIDsForUser(ctx context.Context, userId string) ([]string, error)
}

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 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) CreateOrUpdateUser

func (a *PostgresAuthService) CreateOrUpdateUser(ctx context.Context, form types.CreateUserForm) (User, error)

func (*PostgresAuthService) DeleteUser

func (a *PostgresAuthService) DeleteUser(ctx *echo.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 types.GetUserPageInput) ([]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, form types.ResetPasswordForm) 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:"-"`
	InitialLoginToken  string    `json:"-"` // Only populated when the account is created.
	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

Jump to

Keyboard shortcuts

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