vikunja-api/pkg/routes/api/v1/user_add_update.go

36 lines
1,021 B
Go
Raw Normal View History

2018-06-10 11:11:41 +02:00
package v1
import (
2018-10-31 13:42:38 +01:00
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/routes/crud"
2018-06-10 11:11:41 +02:00
"github.com/labstack/echo"
"net/http"
)
// RegisterUser is the register handler
// @Summary Register
// @Description Creates a new user account.
// @tags user
// @Accept json
// @Produce json
// @Param credentials body models.APIUserPassword true "The user credentials"
// @Success 200 {object} models.User
// @Failure 400 {object} models.HTTPError "No or invalid user register object provided / User already exists."
// @Failure 500 {object} models.Message "Internal error"
// @Router /register [post]
2018-06-13 13:45:22 +02:00
func RegisterUser(c echo.Context) error {
2018-06-10 11:11:41 +02:00
// Check for Request Content
2018-07-10 14:02:23 +02:00
var datUser *models.APIUserPassword
2018-06-13 13:45:22 +02:00
if err := c.Bind(&datUser); err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"No or invalid user model provided."})
2018-06-10 11:11:41 +02:00
}
// Insert the user
newUser, err := models.CreateUser(datUser.APIFormat())
2018-06-10 11:11:41 +02:00
if err != nil {
2018-10-06 15:04:14 +02:00
return crud.HandleHTTPError(err)
2018-06-10 11:11:41 +02:00
}
return c.JSON(http.StatusOK, newUser)
}