auth

package
v0.9.18 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginInput

type LoginInput struct {
	Email       string `json:"email,omitempty"`
	MemberName  string `json:"membername,omitempty"`
	Password    string `json:"password"`
	SessionTime int32  `json:"session_time" default:"30"` // in minutes. Setting to 2^31-1 is used to keep user signed in
}

LoginInput is the input for the login request

func (LoginInput) Validate

func (l LoginInput) Validate() (*member.Input, error)

type RegLoginInput

type RegLoginInput interface {
	RegisterInput | LoginInput
}

RegLoginInput is an union (feature introduced in Go 1.18) of RegisterInput and LoginInput

type RegisterInput

type RegisterInput struct {
	Email      string `json:"email"`
	MemberName string `json:"membername"`
	// Password is first temporarily encrypted using RSA and then hashed using argon2id
	// For more details see the internal/crypt package
	Password        string   `json:"password"`
	PasswordConfirm string   `json:"passwordConfirm"`
	Roles           []string `json:"roles"`
}

RegisterInput is the input for the registration request

func (RegisterInput) Validate

func (r RegisterInput) Validate() (*member.Input, error)

nolint:gocritic

type Service added in v0.6.2

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

Service allows dependency injection for the controller methods, so that the db connection needn't be created in the controller methods

func NewService added in v0.6.2

func NewService(
	conf *cfg.Config,
	ms member.Storer,
	log *zerolog.Logger,
	sess *session.Store,
) *Service

NewService creates an instance of the Service struct and returns a pointer to it It should be used within the routes package where the db connection and config are passed from the main package

func (*Service) ChangePassword added in v0.9.10

func (a *Service) ChangePassword(c *fiber.Ctx) error

@Summary Change password @Description Change the password for the currently logged in user @Tags auth,accounts,updating,settings @Accept json @Produce json @Param old body string true "The old password" @Param new body string true "The new password" @Param X-CSRF-Token header string true "CSRF protection token" @Param Authorization header string true "JWT token" @Router /authenticate/password [patch]

func (*Service) DeleteAccount added in v0.9.10

func (a *Service) DeleteAccount(c *fiber.Ctx) error

@Summary Delete account @Description Delete the account of the currently logged in user @Tags auth,accounts,deleting,settings @Accept json @Param password body string true "The password" @Param confirmation body string true "Confirmation of the password" @Param X-CSRF-Token header string true "CSRF protection token" @Param Authorization header string true "JWT token" @Router /authenticate/delete-account [post]

func (*Service) GetAuthStatus added in v0.7.0

func (a *Service) GetAuthStatus(c *fiber.Ctx) error

func (*Service) Login added in v0.6.2

func (a *Service) Login(c *fiber.Ctx) error

1. Parse the input 2. Validate the input (check for empty fields, valid email, etc.) 3. Pass the email to the database, get the password hash for the email or nickname 4. Compare the password hash with the password hash from the database @Summary Login to the application @Description Create a session for the user @Tags auth,accounts @Accept multipart/form-data @Produce json @Param membername query string false "Member name. Request must include either membername or email" @Param email query string false "Email address" @Param session_time query int false "Session time in minutes" default(30) minimum(1) maximum(2147483647) @Param password query string true "Password" @Param Referrer-Policy header string false "Referrer-Policy header" "no-referrer-when-downgrade" @Param X-CSRF-Token header string true "X-CSRF-Token header" @Success 200 {object} h.ResponseHTTP{data=SessionResponse} @Failure 400 {object} h.ResponseHTTP{} @Failure 401 {object} h.ResponseHTTP{} @Failure 500 {object} h.ResponseHTTP{} @Router /authenticate/login [post]

func (*Service) Logout added in v0.7.0

func (a *Service) Logout(c *fiber.Ctx) error

func (*Service) Register added in v0.6.2

func (a *Service) Register(c *fiber.Ctx) error

Register handles the creation of a new user

type SessionData added in v0.7.3

type SessionData struct {
	IP         string    `json:"ip"`
	UserAgent  string    `json:"user_agent"`
	DeviceUUID uuid.UUID `json:"device_uuid"`
	FirstSeen  time.Time `json:"first_seen"`
	LastSeen   time.Time `json:"last_seen"`
}

type SessionResponse added in v0.9.0

type SessionResponse struct {
	Token      string `json:"token" example:"[A-Za-z0-9]{37}.[A-Za-z0-9]{147}.L-[A-Za-z0-9]{24}_[A-Za-z0-9]{25}-zNjCwGMr-[A-Za-z0-9]{27}"`
	MemberName string `json:"membername" example:"lain"`
}

type Validator

type Validator interface {
	Validate() (*member.Input, error)
}

Jump to

Keyboard shortcuts

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