accounts

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

ErrInvalidCredentials is returned when login credentials are invalid.

View Source
var ErrNoAccountFound = errors.New("no account found")

ErrNoAccountFound is returned when no account is found for a given ID.

Functions

func ConfirmEmail added in v0.3.0

func ConfirmEmail(c *gin.Context)

Confirm email address @Summary Confirm email address @Description Confirm email address by providing username and email @Tags Public @Produce json @Success 200 {object} apitypes.OkResponse @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /confirmemail [get]

func DeleteAccountByID

func DeleteAccountByID(c *gin.Context)

Delete account by ID @Summary [ADMIN] Delete account by ID @Description Delete account by ID - for admin use only @Security Bearer @Tags Internal @Produce json @Param id path int true "Account ID" @Success 200 {object} apitypes.OkResponse @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/accounts/{id} [delete]

func FindUserIDByUsername added in v0.15.0

func FindUserIDByUsername(users []User, username string) uint

FindUserIDByUsername finds a user ID by username Returns 0 if not found

func ForgotPassword added in v0.3.0

func ForgotPassword(c *gin.Context)

Reset password @Summary Reset password @Description Send a new password to the user's email @Tags Public @Accept json @Produce json @Param input body ForgotPasswordInput true "Email Address" @Success 200 {object} apitypes.OkResponse @Failure 400 {object} apitypes.ErrorResponse "Bad Request" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /forgotpassword [post]

func GetAccountByID

func GetAccountByID(c *gin.Context)

Get account by ID @Summary [ADMIN] Get account by ID @Description Get account by ID - for admin use only @Security Bearer @Tags Internal @Produce json @Param id path int true "Account ID" @Success 200 {object} Account @Failure 400 {object} apitypes.ErrorResponse @Failure 404 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/accounts/{id} [get]

func GetAccounts

func GetAccounts(c *gin.Context)

Get all accounts @Summary [ADMIN] Get all accounts @Description Get all accounts - for admin use only @Security Bearer @Tags Internal @Produce json @Success 200 {object} Account @Failure 500 {object} apitypes.ErrorResponse @Router /admin/accounts [get]

func GetMyAccount

func GetMyAccount(c *gin.Context)

Get my account information @Summary Get account info @Description Get information of the currently logged-in user @Security Bearer @Tags Accounts @Produce json @Success 200 {object} Account "Account Information" @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 404 {object} apitypes.ErrorResponse "Account not found" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/myaccount [get]

func Login

func Login(c *gin.Context)

User login @Summary User login @Description Log in a user by providing username and password @Description Returns access token (short-lived) and refresh token (long-lived) @Description Use remember_me to extend refresh token lifetime @Tags Public @Accept json @Produce json @Param input body LoginInput true "Credentials Info" @Success 200 {object} security.TokenPairResponse "Login successful with access and refresh tokens" @Failure 400 {object} apitypes.ErrorResponse "Bad request" @Failure 401 {object} apitypes.ErrorResponse "Invalid credentials or account not confirmed" @Failure 500 {object} apitypes.ErrorResponse "Internal server error" @Router /login [post]

func PostAccount

func PostAccount(c *gin.Context)

Create a new account @Summary [ADMIN] Create a new account @Description Create a new account - for admin use only @Security Bearer @Tags Internal @Accept json @Produce json @Param input body Account true "Account Information" @Success 201 {object} Account @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/accounts [post]

func PutAccountByID

func PutAccountByID(c *gin.Context)

Update account by ID @Summary [ADMIN] Update account by ID @Description Update account by ID - for admin use only @Security Bearer @Tags Internal @Accept json @Produce json @Param id path int true "Account ID" @Param input body Account true "Account Information" @Success 200 {object} Account @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/accounts/{id} [put]

func PutMyAccount

func PutMyAccount(c *gin.Context)

Update my account information @Summary Update account info @Description Update information of the currently logged-in user (email, name, preferences only) @Security Bearer @Tags Accounts @Accept json @Produce json @Param input body AccountUpdateInput true "Account update data (excludes role, status, username)" @Success 200 {object} Account @Failure 400 {object} apitypes.ErrorResponse @Failure 401 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /v1/myaccount [put]

func PutMyPassword

func PutMyPassword(c *gin.Context)

Update user password @Summary Update password @Description Update the password of the current logged-in user @Security Bearer @Tags Accounts @Accept json @Produce json @Param password body PasswordUpdateInput true "Current and New Password" @Success 200 {object} apitypes.OkResponse "Password updated" @Failure 400 {object} apitypes.ErrorResponse "Bad Request" @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/mypassword [put]

func Register

func Register(c *gin.Context)

Register a new user account @Summary Register new user @Description Register a new user with username, password, email, firstname, and lastname @Tags Public @Accept json @Produce json @Param input body RegisterInput true "Register Informations" @Success 200 {object} apitypes.OkResponse @Failure 400 {object} apitypes.ErrorResponse @Router /register [post]

func ResendConfirmEmail added in v1.3.0

func ResendConfirmEmail(c *gin.Context)

Resend confirmation email @Summary Resend confirmation email @Description Resend confirmation email to a pending user account. Always returns 200 to prevent user enumeration. @Tags Public @Accept json @Produce json @Param input body ResendConfirmEmailInput true "Email Address" @Success 200 {object} apitypes.OkResponse @Failure 400 {object} apitypes.ErrorResponse "Bad Request" @Router /resend-confirmemail [post]

Types

type Account added in v0.15.0

type Account struct {
	ID                  uint      `json:"id"`
	Username            string    `json:"username"`
	Email               string    `json:"email"`
	Firstname           string    `json:"firstname"`
	Lastname            string    `json:"lastname"`
	Role                string    `json:"role"`
	Status              string    `json:"status"`
	PreferredCurrency   string    `json:"preferred_currency"`
	PreferredUnitSystem string    `json:"preferred_unit_system"`
	YoutubeURL          *string   `json:"youtube_url"`
	InstagramURL        *string   `json:"instagram_url"`
	HasProfileImage     bool      `json:"has_profile_image"`
	CreatedAt           time.Time `json:"created_at"`
	UpdatedAt           time.Time `json:"updated_at"`
}

Account represents a user account with public information

type AccountUpdateInput added in v1.0.0

type AccountUpdateInput struct {
	Email               string  `json:"email" binding:"required"`
	Firstname           string  `json:"firstname" binding:"required"`
	Lastname            string  `json:"lastname" binding:"required"`
	PreferredCurrency   string  `json:"preferred_currency"`
	PreferredUnitSystem string  `json:"preferred_unit_system"`
	YoutubeURL          *string `json:"youtube_url"`
	InstagramURL        *string `json:"instagram_url"`
}

AccountUpdateInput represents the data users can update about their own account SECURITY: This type intentionally excludes role, status, username, and password fields to prevent privilege escalation and unauthorized modifications

type Accounts added in v0.15.0

type Accounts []Account

Accounts represents a collection of accounts

type ForgotPasswordInput added in v0.15.0

type ForgotPasswordInput struct {
	Email string `json:"email" binding:"required"`
}

ForgotPasswordInput represents the data required to reset a password

type LoginInput added in v0.15.0

type LoginInput struct {
	Username   string `json:"username" binding:"required"`
	Password   string `json:"password" binding:"required"`
	RememberMe bool   `json:"remember_me"` // optional, defaults to false
}

LoginInput represents the data required to login

type PasswordUpdateInput added in v0.15.0

type PasswordUpdateInput struct {
	CurrentPassword string `json:"current_password" binding:"required"`
	NewPassword     string `json:"new_password" binding:"required"`
}

PasswordUpdateInput represents the data required to update a password

type RegisterInput added in v0.15.0

type RegisterInput struct {
	Username  string `json:"username" binding:"required"`
	Password  string `json:"password" binding:"required"`
	Email     string `json:"email" binding:"required"`
	Firstname string `json:"firstname" binding:"required"`
	Lastname  string `json:"lastname" binding:"required"`
}

RegisterInput represents the data required to register a new account

type ResendConfirmEmailInput added in v1.3.0

type ResendConfirmEmailInput struct {
	Email string `json:"email" binding:"required"`
}

ResendConfirmEmailInput represents the data required to resend a confirmation email

type Token added in v0.15.0

type Token struct {
	Token string `json:"token"`
}

Token represents an authentication token

type User added in v0.15.0

type User struct {
	ID                  uint      `json:"id"`
	Username            string    `json:"username"`
	Email               string    `json:"email"`
	Firstname           string    `json:"firstname"`
	Lastname            string    `json:"lastname"`
	Role                string    `json:"role"`
	Status              string    `json:"status"`
	Password            string    `json:"password"`
	LastPassword        string    `json:"last_password"`
	PreferredCurrency   string    `json:"preferred_currency"`
	PreferredUnitSystem string    `json:"preferred_unit_system"`
	CreatedAt           time.Time `json:"created_at"`
	UpdatedAt           time.Time `json:"updated_at"`
}

User represents a user with authentication information

Jump to

Keyboard shortcuts

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