feat: new general and auth errors;

feat: NewPointer helper function in utils;
refactor: length validation in auth models
This commit is contained in:
2025-06-30 01:34:59 +03:00
parent e2d83aa779
commit 284d959bc3
4 changed files with 10 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ import (
var ( var (
ErrUnauthorized = errors.New("User is not authorized") ErrUnauthorized = errors.New("User is not authorized")
ErrUsernameTaken = errors.New("Provided username is already in use") ErrUsernameTaken = errors.New("Provided username is already in use")
ErrUserNotFound = errors.New("User was not found")
ErrInvalidCredentials = errors.New("Invalid username, password or TOTP code") ErrInvalidCredentials = errors.New("Invalid username, password or TOTP code")
ErrInvalidToken = errors.New("Token is invalid or expired") ErrInvalidToken = errors.New("Token is invalid or expired")
ErrServerError = errors.New("Internal server error") ErrServerError = errors.New("Internal server error")

View File

@@ -24,4 +24,5 @@ import (
var ( var (
ErrNotImplemented = errors.New("Feature is not implemented") ErrNotImplemented = errors.New("Feature is not implemented")
ErrBadRequest = errors.New("Bad request") ErrBadRequest = errors.New("Bad request")
ErrForbidden = errors.New("Access is denied")
) )

View File

@@ -28,9 +28,8 @@ type RegistrationBeginRequest struct {
Password string `json:"password" binding:"required"` // TODO: password checking Password string `json:"password" binding:"required"` // TODO: password checking
} }
// TODO: length check
type RegistrationCompleteRequest struct { type RegistrationCompleteRequest struct {
Username string `json:"username" binding:"required"` Username string `json:"username" binding:"required,min=3,max=20"`
VerificationCode string `json:"verification_code" binding:"required"` VerificationCode string `json:"verification_code" binding:"required"`
Name string `json:"name" binding:"required,max=75"` Name string `json:"name" binding:"required,max=75"`
Birthday *string `json:"birthday"` Birthday *string `json:"birthday"`
@@ -41,10 +40,9 @@ type RegistrationCompleteResponse struct {
Tokens Tokens
} }
// TODO: length check
type LoginRequest struct { type LoginRequest struct {
Username string `json:"username" binding:"required"` Username string `json:"username" binding:"required,min=3,max=20"`
Password string `json:"password" binding:"required"` Password string `json:"password" binding:"required,max=100"`
TOTP *string `json:"totp"` TOTP *string `json:"totp"`
} }

View File

@@ -0,0 +1,5 @@
package utils
func NewPointer[T any](d T) *T {
return &d
}