@@ -0,0 +1,75 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// RegisterUser creates an inactive user account.
|
||||
func (c *Client) RegisterUser(ctx context.Context, input RegisterUserInput) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPost, "v1/users", input, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// ActivateUser activates an account using a plaintext activation token.
|
||||
func (c *Client) ActivateUser(ctx context.Context, token string) (User, *Response, error) {
|
||||
return c.activateUser(ctx, map[string]string{"token": token})
|
||||
}
|
||||
|
||||
// ActivateInvitedUser activates an account and sets its initial password.
|
||||
func (c *Client) ActivateInvitedUser(ctx context.Context, token, password string) (User, *Response, error) {
|
||||
return c.activateUser(ctx, map[string]string{"token": token, "password": password})
|
||||
}
|
||||
|
||||
func (c *Client) activateUser(ctx context.Context, input any) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPut, "v1/users/activated", input, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// UpdatePassword replaces a password using a valid reset token.
|
||||
func (c *Client) UpdatePassword(ctx context.Context, input UpdatePasswordInput) (string, *Response, error) {
|
||||
var envelope struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPut, "v1/users/password", input, &envelope)
|
||||
return envelope.Message, response, err
|
||||
}
|
||||
|
||||
// AdminUsers lists all non-deleted user accounts.
|
||||
func (c *Client) AdminUsers(ctx context.Context) ([]User, *Response, error) {
|
||||
var envelope struct {
|
||||
Users []User `json:"users"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodGet, "v1/admin/users", nil, &envelope)
|
||||
return envelope.Users, response, err
|
||||
}
|
||||
|
||||
// InviteAdminUser creates an inactive account and sends its invitation.
|
||||
func (c *Client) InviteAdminUser(ctx context.Context, input AdminUserInviteInput) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPost, "v1/admin/users", input, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// UpdateAdminUserRole changes an account's application role.
|
||||
func (c *Client) UpdateAdminUserRole(ctx context.Context, userID int, role string) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPatch, "v1/admin/users/"+strconv.Itoa(userID), map[string]string{"role": role}, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// DeleteAdminUser permanently anonymizes and deactivates an account.
|
||||
func (c *Client) DeleteAdminUser(ctx context.Context, userID int) (*Response, error) {
|
||||
return c.do(ctx, http.MethodDelete, "v1/admin/users/"+strconv.Itoa(userID), nil, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user