2018-10-27 15:14:55 +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-10-27 15:14:55 +02:00
|
|
|
"github.com/labstack/echo"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UserConfirmEmail is the handler to confirm a user email
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Confirm the email of a new user
|
|
|
|
// @Description Confirms the email of a newly registered user.
|
|
|
|
// @tags user
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param credentials body models.EmailConfirm true "The token."
|
|
|
|
// @Success 200 {object} models.Message
|
|
|
|
// @Failure 412 {object} models.HTTPError "Bad token provided."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /user/confirm [post]
|
2018-10-27 15:14:55 +02:00
|
|
|
func UserConfirmEmail(c echo.Context) error {
|
|
|
|
// Check for Request Content
|
|
|
|
var emailConfirm models.EmailConfirm
|
|
|
|
if err := c.Bind(&emailConfirm); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "No token provided.")
|
|
|
|
}
|
|
|
|
|
|
|
|
err := models.UserEmailConfirm(&emailConfirm)
|
|
|
|
if err != nil {
|
|
|
|
return crud.HandleHTTPError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, models.Message{"The email was confirmed successfully."})
|
|
|
|
}
|