diff --git a/backend/internal/errors/auth.go b/backend/internal/errors/auth.go index 5d2a4f1..36f89fe 100644 --- a/backend/internal/errors/auth.go +++ b/backend/internal/errors/auth.go @@ -24,6 +24,7 @@ import ( var ( ErrUnauthorized = errors.New("User is not authorized") 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") ErrInvalidToken = errors.New("Token is invalid or expired") ErrServerError = errors.New("Internal server error") diff --git a/backend/internal/errors/general.go b/backend/internal/errors/general.go index e3bdc79..641a4f6 100644 --- a/backend/internal/errors/general.go +++ b/backend/internal/errors/general.go @@ -24,4 +24,5 @@ import ( var ( ErrNotImplemented = errors.New("Feature is not implemented") ErrBadRequest = errors.New("Bad request") + ErrForbidden = errors.New("Access is denied") ) diff --git a/backend/internal/models/auth.go b/backend/internal/models/auth.go index 1d63a09..5532009 100644 --- a/backend/internal/models/auth.go +++ b/backend/internal/models/auth.go @@ -28,9 +28,8 @@ type RegistrationBeginRequest struct { Password string `json:"password" binding:"required"` // TODO: password checking } -// TODO: length check 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"` Name string `json:"name" binding:"required,max=75"` Birthday *string `json:"birthday"` @@ -41,10 +40,9 @@ type RegistrationCompleteResponse struct { Tokens } -// TODO: length check type LoginRequest struct { - Username string `json:"username" binding:"required"` - Password string `json:"password" binding:"required"` + Username string `json:"username" binding:"required,min=3,max=20"` + Password string `json:"password" binding:"required,max=100"` TOTP *string `json:"totp"` } diff --git a/backend/internal/utils/pointer.go b/backend/internal/utils/pointer.go new file mode 100644 index 0000000..c6cd178 --- /dev/null +++ b/backend/internal/utils/pointer.go @@ -0,0 +1,5 @@ +package utils + +func NewPointer[T any](d T) *T { + return &d +}