forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
user.go
45 lines (35 loc) · 1016 Bytes
/
user.go
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
package dtrack
import (
"context"
"net/http"
"net/url"
)
type UserService struct {
client *Client
}
func (us UserService) Login(ctx context.Context, username, password string) (token string, err error) {
body := url.Values{}
body.Set("username", username)
body.Set("password", password)
req, err := us.client.newRequest(ctx, http.MethodPost, "/api/v1/user/login", withBody(body))
if err != nil {
return
}
req.Header.Set("Accept", "*/*")
_, err = us.client.doRequest(req, &token)
return
}
func (us UserService) ForceChangePassword(ctx context.Context, username, password, newPassword string) (err error) {
body := url.Values{}
body.Set("username", username)
body.Set("password", password)
body.Set("newPassword", newPassword)
body.Set("confirmPassword", newPassword)
req, err := us.client.newRequest(ctx, http.MethodPost, "/api/v1/user/forceChangePassword", withBody(body))
if err != nil {
return
}
req.Header.Set("Accept", "*/*")
_, err = us.client.doRequest(req, nil)
return
}