Documentation
¶
Overview ¶
Package controllers provides the controllers for the API
Index ¶
- type ActivateTOTPRequest
- type AuthenticationController
- type ChangePasswordRequest
- type ChannelController
- type DBInterface
- type DisableTOTPRequest
- type EnrollTOTPRequest
- type EnrollTOTPResponse
- type HealthCheckController
- type HealthCheckResponse
- type LoginResponse
- type PoolInterface
- type RedisInterface
- type Role
- type UserChannelResponse
- type UserController
- func (ctr *UserController) ActivateTOTP(c echo.Context) error
- func (ctr *UserController) ChangePassword(c echo.Context) error
- func (ctr *UserController) DisableTOTP(c echo.Context) error
- func (ctr *UserController) EnrollTOTP(c echo.Context) error
- func (ctr *UserController) GetCurrentUser(c echo.Context) error
- func (ctr *UserController) GetUser(c echo.Context) error
- func (ctr *UserController) GetUserChannels(c echo.Context) error
- func (ctr *UserController) GetUserRoles(c echo.Context) error
- type UserRegisterActivateRequest
- type UserRegisterActivateResponse
- type UserRegisterController
- type UserRegisterRequest
- type UserResponse
- type UserRolesResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivateTOTPRequest ¶ added in v0.2.0
type ActivateTOTPRequest struct {
OTPCode string `json:"otp_code" validate:"required,len=6,numeric" extensions:"x-order=0"`
}
ActivateTOTPRequest defines the request payload for 2FA activation
type AuthenticationController ¶
type AuthenticationController struct {
// contains filtered or unexported fields
}
AuthenticationController is the controller for the authentication routes
func NewAuthenticationController ¶
func NewAuthenticationController( s models.Querier, rdb *redis.Client, t func() time.Time, ) *AuthenticationController
NewAuthenticationController returns a new AuthenticationController
func (*AuthenticationController) Login ¶
func (ctr *AuthenticationController) Login(c echo.Context) error
Login godoc @Summary Login @Description Authenticates a user and returns an authentication token, which can be a JWT token or a state token. @Description If the user has enabled multi-factor authentication (MFA), a state token will be returned instead of a JWT token. @Description The state token is used in conjunction with the OTP (one-time password) to retrieve the actual JWT token. @Description To obtain the JWT token, the state token and OTP must be sent to the `/authn/verify_factor` endpoint. @Tags auth @Accept json @Produce json @Param data body loginRequest true "Login request" @Success 200 {object} LoginResponse @Failure 401 {object} customError "Invalid username or password" @Router /login [post]
func (*AuthenticationController) Logout ¶
func (ctr *AuthenticationController) Logout(c echo.Context) error
Logout godoc @Summary Logout @Description Logs out the user by deleting the refresh token from the database. If `{logout_all: true}` is posted, @Description all refresh tokens for the user will be deleted, invalidating all refresh tokens. @Tags auth @Accept json @Produce json @Param data body logoutRequest true "Logout request" @Success 200 {string} string "Logged out" @Failure 401 {object} customError "Unauthorized" @Security JWTBearerToken @Router /logout [post]
func (*AuthenticationController) RefreshToken ¶
func (ctr *AuthenticationController) RefreshToken(c echo.Context) error
RefreshToken godoc @Summary Refresh JWT token @Description Refreshes the JWT token using the refresh token stored in the client's cookie. @Tags auth @Accept json @Produce json @Success 200 {object} LoginResponse @Failure 400 {object} customError "Bad request" @Failure 401 {object} customError "Unauthorized" @Router /authn/refresh [post]
func (*AuthenticationController) VerifyFactor ¶ added in v0.0.2
func (ctr *AuthenticationController) VerifyFactor(c echo.Context) error
VerifyFactor is used to verify the user factor (OTP) @Summary Verify MFA factor @Description Verifies the user's MFA factor (OTP) and returns a JWT token if successful. @Description The state token, returned from `/login` if the user has TOTP enabled, it is used in conjunction with @Description the OTP (one-time password) to retrieve the actual JWT token @Tags auth @Accept json @Produce json @Param data body factorRequest true "State token and OTP" @Success 200 {object} LoginResponse @Failure 400 {object} customError "Bad request" @Failure 401 {object} customError "Unauthorized" @Router /authn/factor_verify [post]
type ChangePasswordRequest ¶ added in v0.2.0
type ChangePasswordRequest struct {
CurrentPassword string `json:"current_password" validate:"required,max=72" extensions:"x-order=0"`
NewPassword string `json:"new_password" validate:"required,min=10,max=72" extensions:"x-order=1"`
ConfirmPassword string `json:"confirm_password" validate:"required,eqfield=NewPassword" extensions:"x-order=2"`
}
ChangePasswordRequest defines the request payload for changing password
type ChannelController ¶
type ChannelController struct {
// contains filtered or unexported fields
}
func NewChannelController ¶
func NewChannelController(s models.Querier) *ChannelController
func (*ChannelController) GetChannel ¶
func (ctr *ChannelController) GetChannel()
type DBInterface ¶ added in v0.0.9
DBInterface defines the interface for database operations
type DisableTOTPRequest ¶ added in v0.2.0
type DisableTOTPRequest struct {
CurrentPassword string `json:"current_password" validate:"required,max=72" extensions:"x-order=0"`
OTPCode string `json:"otp_code" validate:"required,len=6,numeric" extensions:"x-order=1"`
}
DisableTOTPRequest defines the request payload for 2FA disabling
type EnrollTOTPRequest ¶ added in v0.2.0
type EnrollTOTPRequest struct {
CurrentPassword string `json:"current_password" validate:"required,max=72" extensions:"x-order=0"`
}
EnrollTOTPRequest defines the request payload for 2FA enrollment
type EnrollTOTPResponse ¶ added in v0.2.0
type EnrollTOTPResponse struct {
QRCodeBase64 string `json:"qr_code_base64" extensions:"x-order=0"`
Secret string `json:"secret" extensions:"x-order=1"`
}
EnrollTOTPResponse defines the response for 2FA enrollment
type HealthCheckController ¶
type HealthCheckController struct {
// contains filtered or unexported fields
}
func NewHealthCheckController ¶
func NewHealthCheckController(dbPool *pgxpool.Pool, rdb *redis.Client) *HealthCheckController
func (*HealthCheckController) HealthCheck ¶
func (ctr *HealthCheckController) HealthCheck(c echo.Context) error
type HealthCheckResponse ¶
type LoginResponse ¶
type LoginResponse struct {
AccessToken string `` /* 219-byte string literal not displayed */
RefreshToken string `` /* 219-byte string literal not displayed */
}
LoginResponse is the response sent to a client upon successful FULL authentication
type PoolInterface ¶ added in v0.1.0
PoolInterface defines the interface for database pool operations
type RedisInterface ¶ added in v0.0.9
RedisInterface defines the interface for Redis operations
type UserChannelResponse ¶
type UserController ¶
type UserController struct {
// contains filtered or unexported fields
}
func NewUserController ¶
func NewUserController(s models.Querier) *UserController
func (*UserController) ActivateTOTP ¶ added in v0.2.0
func (ctr *UserController) ActivateTOTP(c echo.Context) error
ActivateTOTP completes 2FA enrollment by validating the provided OTP code @Summary Complete 2FA enrollment @Description Validates the OTP code and activates 2FA for the user account @Tags user @Accept json @Produce json @Param data body ActivateTOTPRequest true "OTP code for 2FA activation" @Success 200 "2FA activated successfully" @Failure 400 "Bad request - validation failed" @Failure 401 "Unauthorized - missing or invalid token" @Failure 403 "Forbidden - invalid OTP code" @Failure 409 "Conflict - 2FA already enabled or not enrolled" @Failure 500 "Internal server error" @Router /user/2fa/activate [post] @Security JWTBearerToken
func (*UserController) ChangePassword ¶ added in v0.2.0
func (ctr *UserController) ChangePassword(c echo.Context) error
ChangePassword allows an authenticated user to change their password @Summary Change user password @Description Changes the password for the currently authenticated user @Tags user @Accept json @Produce json @Param data body ChangePasswordRequest true "Password change request" @Success 200 {string} string "Password changed successfully" @Failure 400 {string} string "Bad request - validation error" @Failure 401 {string} string "Unauthorized - invalid current password" @Failure 404 {string} string "User not found" @Failure 500 {string} string "Internal server error" @Router /user/password [put] @Security JWTBearerToken
func (*UserController) DisableTOTP ¶ added in v0.2.0
func (ctr *UserController) DisableTOTP(c echo.Context) error
DisableTOTP disables 2FA for the authenticated user @Summary Disable 2FA @Description Disables 2FA for the user account. Requires both current password and valid OTP code for security. @Tags user @Accept json @Produce json @Param data body DisableTOTPRequest true "Password and OTP code for 2FA disabling" @Success 200 "2FA disabled successfully" @Failure 400 "Bad request - validation failed" @Failure 401 "Unauthorized - missing or invalid token" @Failure 403 "Forbidden - incorrect password or invalid OTP" @Failure 409 "Conflict - 2FA is not enabled" @Failure 500 "Internal server error" @Router /user/2fa/disable [post] @Security JWTBearerToken
func (*UserController) EnrollTOTP ¶ added in v0.2.0
func (ctr *UserController) EnrollTOTP(c echo.Context) error
EnrollTOTP allows an authenticated user to start 2FA enrollment by generating a QR code @Summary Start 2FA enrollment @Description Generates a QR code and secret for TOTP 2FA enrollment. Requires current password for security. @Tags user @Accept json @Produce json @Param data body EnrollTOTPRequest true "Password confirmation for 2FA enrollment" @Success 200 {object} EnrollTOTPResponse @Failure 400 "Bad request - validation failed" @Failure 401 "Unauthorized - missing or invalid token" @Failure 403 "Forbidden - incorrect password" @Failure 409 "Conflict - 2FA already enabled" @Failure 500 "Internal server error" @Router /user/2fa/enroll [post] @Security JWTBearerToken
func (*UserController) GetCurrentUser ¶ added in v0.1.0
func (ctr *UserController) GetCurrentUser(c echo.Context) error
GetCurrentUser returns detailed information about the current authenticated user @Summary Get current user information @Description Get current user information @Tags user @Accept json @Produce json @Success 200 {object} UserResponse @Failure 401 "Authorization information is missing or invalid." @Failure 404 "User not found." @Failure 500 "Internal server error." @Router /user [get] @Security JWTBearerToken
func (*UserController) GetUser ¶
func (ctr *UserController) GetUser(c echo.Context) error
GetUser returns a user by id @Summary Get user data by id @Description Returns a user by id @Tags users @Produce json @Param id path int true "User ID" @Success 200 {object} UserResponse @Router /users/{id} [get] @Security JWTBearerToken
func (*UserController) GetUserChannels ¶ added in v0.0.8
func (ctr *UserController) GetUserChannels(c echo.Context) error
func (*UserController) GetUserRoles ¶ added in v0.0.6
func (ctr *UserController) GetUserRoles(c echo.Context) error
GetUserRoles returns the roles for a given user @Summary Get the roles for a given user @Description Get the roles for a given user @Tags users @Produce json @Param id path int true "User ID" @Success 200 {object} UserRolesResponse @Failure 400 {string} string "Invalid user ID" @Failure 404 {string} string "User not found" @Failure 500 {string} string "Internal server error" @Router /users/{id}/roles [get] @Security JWTBearerToken
type UserRegisterActivateRequest ¶ added in v0.1.0
type UserRegisterActivateRequest struct {
Token string `json:"token" validate:"required" extensions:"x-order=0"`
}
UserActivateRequest is the request body for the activate endpoint
type UserRegisterActivateResponse ¶ added in v0.1.0
type UserRegisterActivateResponse struct {
Username string `json:"username" extensions:"x-order=0"`
Email string `json:"email" extensions:"x-order=1"`
}
UserActivateAccountResponse is the response sent to a client upon successful account activation
type UserRegisterController ¶ added in v0.1.0
type UserRegisterController struct {
// contains filtered or unexported fields
}
UserRegisterController is the controller for the authentication routes
func NewUserRegisterController ¶ added in v0.1.0
func NewUserRegisterController(s models.ServiceInterface, pool PoolInterface) *UserRegisterController
NewUserRegisterController returns a new UserRegisterController
func (*UserRegisterController) UserActivateAccount ¶ added in v0.1.0
func (ctr *UserRegisterController) UserActivateAccount(c echo.Context) error
UserActivateAccount godoc @Summary Activate user account @Description Activates a user account using the provided token. @Tags auth @Accept json @Produce json @Param data body UserRegisterActivateRequest true "Activate account request" @Success 200 {object} UserRegisterActivateResponse @Failure 400 {object} customError "Bad request" @Failure 401 {object} customError "Unauthorized" @Failure 404 {object} customError "Not found" @Failure 500 {object} customError "Internal server error" @Router /activate [post]
func (*UserRegisterController) UserRegister ¶ added in v0.1.0
func (ctr *UserRegisterController) UserRegister(c echo.Context) error
UserRegister example @Summary Register @Description Creates a new user account. @Tags auth @Accept json @Produce json @Param data body UserRegisterRequest true "Register request" @Success 201 "User created" @Failure 400 {object} customError "Bad request" @Failure 500 {object} customError "Internal server error" @Router /register [post]
type UserRegisterRequest ¶ added in v0.1.0
type UserRegisterRequest struct {
Username string `json:"username" validate:"required,min=2,max=12" extensions:"x-order=0"`
Password string `json:"password" validate:"required,min=10,max=72" extensions:"x-order=1"`
ConfirmPassword string `json:"confirm_password" validate:"required,eqfield=Password" extensions:"x-order=2"`
Email string `json:"email" validate:"required,email" extensions:"x-order=3"`
AUP bool `json:"aup" validate:"required,eq=true" extensions:"x-order=4"`
COPPA bool `json:"coppa" validate:"required,eq=true" extensions:"x-order=5"`
}
RegisterRequest is the request body for the register route
type UserResponse ¶
type UserResponse struct {
ID int32 `json:"id" extensions:"x-order=0"`
Username string `json:"username" extensions:"x-order=1"`
Email string `json:"email,omitempty" extensions:"x-order=2"`
MaxLogins int32 `json:"max_logins" extensions:"x-order=3"`
LanguageCode string `json:"language_code,omitempty" extensions:"x-order=4"`
LanguageName string `json:"language_name,omitempty" extensions:"x-order=5"`
LastSeen int32 `json:"last_seen,omitempty" extensions:"x-order=6"`
TotpEnabled bool `json:"totp_enabled" extensions:"x-order=7"`
Channels []UserChannelResponse `json:"channels,omitempty" extensions:"x-order=8"`
}