diff --git a/backend/internal/controllers/auth.go b/backend/internal/controllers/auth.go index 46661cc..b98f52a 100644 --- a/backend/internal/controllers/auth.go +++ b/backend/internal/controllers/auth.go @@ -59,7 +59,25 @@ func NewAuthController(_log *zap.Logger, as services.AuthService) AuthController // @Success 200 {object} models.LoginResponse "desc" // @Router /auth/login [post] func (a *authControllerImpl) Login(c *gin.Context) { - c.Status(http.StatusNotImplemented) + request, ok := utils.GetRequest[models.LoginRequest](c) + if !ok { + c.Status(http.StatusBadRequest) + return + } + + _, err := a.authService.Login(request.Body) + + if err != nil { + if errors.Is(err, errs.ErrForbidden) { + c.Status(http.StatusForbidden) + } else { + c.Status(http.StatusInternalServerError) + } + return + } + + c.Status(http.StatusOK) + return } // PasswordResetBegin implements AuthController. @@ -158,7 +176,7 @@ func (a *authControllerImpl) RegistrationComplete(c *gin.Context) { func (a *authControllerImpl) RegisterRoutes(group *gin.RouterGroup) { group.POST("/registrationBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.RegistrationBegin) group.POST("/registrationComplete", middleware.RequestMiddleware[models.RegistrationCompleteRequest](enums.GuestRole), a.RegistrationComplete) - group.POST("/login", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.Login) + group.POST("/login", middleware.RequestMiddleware[models.LoginRequest](enums.GuestRole), a.Login) group.POST("/refresh", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.UserRole), a.Refresh) group.POST("/passwordResetBegin", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetBegin) group.POST("/passwordResetComplete", middleware.RequestMiddleware[models.RegistrationBeginRequest](enums.GuestRole), a.PasswordResetComplete) diff --git a/backend/internal/validation/custom.go b/backend/internal/validation/custom.go index 8941633..5addea2 100644 --- a/backend/internal/validation/custom.go +++ b/backend/internal/validation/custom.go @@ -44,7 +44,7 @@ func GetCustomHandlers() []CustomValidatorHandler { FieldName: "name", Function: func(fl validator.FieldLevel) bool { username := fl.Field().String() - return regexp.MustCompile(`^[.]{1,75}$`).MatchString(username) + return regexp.MustCompile(`^.{1,75}$`).MatchString(username) }}, { diff --git a/sqlc/schema.sql b/sqlc/schema.sql index 55ed0de..3e6c2df 100644 --- a/sqlc/schema.sql +++ b/sqlc/schema.sql @@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS "confirmation_codes" ( CREATE TABLE IF NOT EXISTS "sessions" ( id BIGSERIAL PRIMARY KEY, - user_id BIGINT UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE, + user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE, guid UUID NOT NULL DEFAULT gen_random_uuid(), name VARCHAR(100), platform VARCHAR(32),