mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-27 22:27:23 +08:00
feat: introduce hanko profile element and related api changes (#495)
* feat: introduce hanko profile element and related api changes
This commit is contained in:
@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user