web

package
v0.0.0-...-71c93ef Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AfterLoginLocation   = "/files"
	UserListLocation     = "/users"
	HomeRedirectLocation = "/"
)

Variables

This section is empty.

Functions

func GetIPAddress

func GetIPAddress(r *http.Request) string

func Parse

func Parse[T any](r *http.Request, into T) (T, error)

func Problem

func Problem(w http.ResponseWriter, logger *log.Logger, err error)

func Send

func Send(w http.ResponseWriter, content interface{})

Types

type AccessChangeRequest

type AccessChangeRequest struct {
	Username string   `json:"username" formam:"username"`
	Access   []string `json:"access"   formam:"access"`
	CSRF     string   `json:"-"        formam:"csrf"`
}

AccessChangeRequest represents an access change request.

type FallbackHandler

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

FallbackHandler handles fallback requests.

func NewFallbackHandler

func NewFallbackHandler(csrfRepo *repo.CSRF, logger *log.Logger) *FallbackHandler

NewFallbackHandler creates a new FallbackHandler.

func (*FallbackHandler) Home

Home handles the home page. Does not expect a valid session.

type FileHandler

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

func NewFileHandler

func NewFileHandler(fileService *service.File, cookie *service.Cookie, logger *log.Logger) *FileHandler

func (*FileHandler) ListFiles

func (fh *FileHandler) ListFiles(w http.ResponseWriter, r *http.Request)

ListFiles lists files.

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" formam:"username"`
	Password string `json:"password" formam:"password"`
	CSRF     string `json:"-"        formam:"csrf"`
}

LoginRequest represents a password change request.

type PasswordChangeRequest

type PasswordChangeRequest struct {
	Username string `json:"username" formam:"username"`
	Password string `json:"password" formam:"password"`
	CSRF     string `json:"-"        formam:"csrf"`
}

PasswordChangeRequest represents a password change request.

type UserHandler

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

UserHandler handles user requests.

func NewUserHandler

func NewUserHandler(userService *service.User, csrfRepo *repo.CSRF, sessionService *service.Cookie, logger *log.Logger) *UserHandler

NewUserHandler creates a new UserHandler.

func (*UserHandler) CreateUser

func (uh *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser creates a new user and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

func (*UserHandler) DeleteUser

func (uh *UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser deletes a user and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

func (*UserHandler) DemoteUser

func (uh *UserHandler) DemoteUser(w http.ResponseWriter, r *http.Request)

DemoteUser demotes a user from admin to regular user and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

func (*UserHandler) ListUsers

func (uh *UserHandler) ListUsers(w http.ResponseWriter, r *http.Request)

ListUsers lists all users. Expects a valid session and admin rights.

func (*UserHandler) Login

func (uh *UserHandler) Login(w http.ResponseWriter, r *http.Request)

Login logs in the user via the HTML form and redirects to the files list page. Expects CSRF, but not a valid session.

func (*UserHandler) PromoteUser

func (uh *UserHandler) PromoteUser(w http.ResponseWriter, r *http.Request)

PromoteUser promotes a user to admin and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

func (*UserHandler) UpdateUserAccess

func (uh *UserHandler) UpdateUserAccess(w http.ResponseWriter, r *http.Request)

UpdateUserAccess updates the access list of a user and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

func (*UserHandler) UpdateUserPassword

func (uh *UserHandler) UpdateUserPassword(w http.ResponseWriter, r *http.Request)

UpdateUserPassword updates the password of a user and redirects to the users list page. Expects a valid session and admin rights. Expects a valid CSRF token.

type UserNameOnlyRequest

type UserNameOnlyRequest struct {
	Username string `json:"username" formam:"username"`
	CSRF     string `json:"-"        formam:"csrf"`
}

UserNameOnlyRequest represents a request where the username is the only mandatory field.

Jump to

Keyboard shortcuts

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