feat(auth): Add login, register, session_info and api creation
This commit is contained in:
35
app/controllers/register.go
Normal file
35
app/controllers/register.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/auth-api/services"
|
||||
"git.secnex.io/secnex/auth-api/utils"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type RegisterRequest struct {
|
||||
FirstName string `json:"first_name" validate:"required"`
|
||||
LastName string `json:"last_name" validate:"required"`
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
}
|
||||
|
||||
func RegisterController(c *fiber.Ctx) error {
|
||||
var request RegisterRequest
|
||||
if err := c.BodyParser(&request); err != nil {
|
||||
return utils.NewErrorResponse(fiber.StatusBadRequest, &fiber.Map{
|
||||
"message": "Invalid request body",
|
||||
}).Send(c)
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(request); err != nil {
|
||||
return utils.NewErrorResponse(fiber.StatusBadRequest, &fiber.Map{
|
||||
"message": "Invalid request body",
|
||||
}).Send(c)
|
||||
}
|
||||
|
||||
response := services.Register(request.FirstName, request.LastName, request.Username, request.Password, request.Email)
|
||||
return response.Send(c)
|
||||
}
|
||||
Reference in New Issue
Block a user