feat: introduce hanko profile element and related api changes (#495)

* feat: introduce hanko profile element and related api changes
This commit is contained in:
bjoern-m
2023-01-25 10:55:23 +01:00
committed by GitHub
parent 93ad9c4056
commit ca62cf421f
254 changed files with 13765 additions and 3955 deletions

View File

@ -10,7 +10,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)
type UserHandlerAdmin struct {
@ -51,52 +50,6 @@ type UserPatchRequest struct {
Verified *bool `json:"verified"`
}
func (h *UserHandlerAdmin) Patch(c echo.Context) error {
var patchRequest UserPatchRequest
if err := c.Bind(&patchRequest); err != nil {
return dto.ToHttpError(err)
}
if err := c.Validate(patchRequest); err != nil {
return dto.ToHttpError(err)
}
patchRequest.Email = strings.ToLower(patchRequest.Email)
p := h.persister.GetUserPersister()
user, err := p.Get(uuid.FromStringOrNil(patchRequest.UserId))
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
if user == nil {
return dto.NewHTTPError(http.StatusNotFound, "user not found")
}
if patchRequest.Email != "" && patchRequest.Email != user.Email {
maybeExistingUser, err := p.GetByEmail(patchRequest.Email)
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
if maybeExistingUser != nil {
return dto.NewHTTPError(http.StatusBadRequest, "email address not available")
}
user.Email = patchRequest.Email
}
if patchRequest.Verified != nil {
user.Verified = *patchRequest.Verified
}
err = p.Update(*user)
if err != nil {
return fmt.Errorf("failed to update user: %w", err)
}
return c.JSON(http.StatusOK, nil) // TODO: mabye we should return the user object???
}
type UserListRequest struct {
PerPage int `query:"per_page"`
Page int `query:"page"`