@@ -0,0 +1,48 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// UpdateAccountProfile changes the current user's display name and color.
|
||||
func (c *Client) UpdateAccountProfile(ctx context.Context, name, color string) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPatch, "v1/account", map[string]string{"name": name, "color": color}, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// UpdateAccountPassword changes the current user's password after verifying the old one.
|
||||
func (c *Client) UpdateAccountPassword(ctx context.Context, currentPassword, newPassword string) (*Response, error) {
|
||||
return c.do(ctx, http.MethodPut, "v1/account/password", map[string]string{"current_password": currentPassword, "new_password": newPassword}, nil)
|
||||
}
|
||||
|
||||
// RequestAccountEmailChange starts email verification after password confirmation.
|
||||
func (c *Client) RequestAccountEmailChange(ctx context.Context, email, currentPassword string) (*Response, error) {
|
||||
return c.do(ctx, http.MethodPost, "v1/account/email", map[string]string{"email": email, "current_password": currentPassword}, nil)
|
||||
}
|
||||
|
||||
// ConfirmAccountEmail applies a pending email change using its verification token.
|
||||
func (c *Client) ConfirmAccountEmail(ctx context.Context, token string) (User, *Response, error) {
|
||||
var envelope struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodPost, "v1/account/email/confirm", map[string]string{"token": token}, &envelope)
|
||||
return envelope.User, response, err
|
||||
}
|
||||
|
||||
// AccountSessions lists the current user's active login sessions.
|
||||
func (c *Client) AccountSessions(ctx context.Context) ([]AccountSession, *Response, error) {
|
||||
var envelope struct {
|
||||
Sessions []AccountSession `json:"sessions"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodGet, "v1/account/sessions", nil, &envelope)
|
||||
return envelope.Sessions, response, err
|
||||
}
|
||||
|
||||
// DeleteAccountSession revokes one login session owned by the current user.
|
||||
func (c *Client) DeleteAccountSession(ctx context.Context, id string) (*Response, error) {
|
||||
return c.do(ctx, http.MethodDelete, "v1/account/sessions/"+id, nil, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user