forked from nscuro/dtrack-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.go
More file actions
54 lines (42 loc) · 1.08 KB
/
Copy pathuser.go
File metadata and controls
54 lines (42 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dtrack
import (
"context"
"net/http"
"net/url"
)
type UserService struct {
client *Client
}
func (u UserService) Login(ctx context.Context, username, password string) (string, error) {
body := url.Values{}
body.Set("username", username)
body.Set("password", password)
req, err := u.client.newRequest(ctx, http.MethodPost, "/api/v1/user/login", withBody(body))
if err != nil {
return "", err
}
req.Header.Set("Accept", "*/*")
var token string
_, err = u.client.doRequest(req, &token)
if err != nil {
return "", err
}
return token, nil
}
func (u UserService) ForceChangePassword(ctx context.Context, username, password, newPassword string) error {
body := url.Values{}
body.Set("username", username)
body.Set("password", password)
body.Set("newPassword", newPassword)
body.Set("confirmPassword", newPassword)
req, err := u.client.newRequest(ctx, http.MethodPost, "/api/v1/user/forceChangePassword", withBody(body))
if err != nil {
return err
}
req.Header.Set("Accept", "*/*")
_, err = u.client.doRequest(req, nil)
if err != nil {
return err
}
return nil
}