2024-05-07 22:03:15 +00:00
|
|
|
package wordpress
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"federated.computer/wp-sync-slowtwitch/utilities"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CreateUser struct {
|
2024-05-21 16:50:05 +00:00
|
|
|
Username string `json:"username"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Roles string `json:"roles"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
LastName string `json:"last_name"`
|
2024-05-07 22:03:15 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 00:52:47 +00:00
|
|
|
type CreateUserResponse struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
LastName string `json:"last_name"`
|
|
|
|
}
|
|
|
|
|
2024-05-17 18:49:55 +00:00
|
|
|
func (parameters *CreateUser) Execute(baseUrl, user, pass string) (CreateUserResponse, error) {
|
2024-05-16 18:50:53 +00:00
|
|
|
endpoint := baseUrl + "wp-json/wp/v2/users"
|
2024-05-17 18:49:55 +00:00
|
|
|
body, err := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
|
|
|
|
if err != nil {
|
|
|
|
return CreateUserResponse{}, err
|
|
|
|
}
|
2024-05-08 01:23:21 +00:00
|
|
|
var userData CreateUserResponse
|
2024-05-17 18:49:55 +00:00
|
|
|
err = json.Unmarshal(body, &userData)
|
|
|
|
if err != nil {
|
|
|
|
return CreateUserResponse{}, err
|
|
|
|
}
|
|
|
|
return userData, nil
|
2024-05-07 22:03:15 +00:00
|
|
|
}
|