cisco/sdk/invite.go -rw-r--r-- 1.1 KiB View raw
                                                                                
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
55
56
57
58
59
60
61
62
63
64
65
66
67
package cisco

import (
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"time"
)

type Invite struct {
	Email   string    `json:"email"`
	Claimed bool      `json:"claimed"`
	Created time.Time `json:"created"`
}

type InviteClaim struct {
	Password string `json:"password"`
	Username string `json:"username"`
}

func ClaimInvite(hash string, username string, password string) error {
	hashedPassword := sha256.Sum256([]byte(password))

	_, err := SendRequest(InviteClaimRoute, Request{
		Arg: hash,
		Data: &InviteClaim{
			Username: username,
			Password: hex.EncodeToString(hashedPassword[:]),
		},
	})

	return err
}

type InviteGet struct {
	Email   string `json:"email"`
	Claimed bool   `json:"claimed"`
}

func GetInvite(hash string) (*InviteGet, error) {
	var invite InviteGet

	data, err := SendRequest(InviteGetRoute, Request{
		Arg: hash,
	})

	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &invite)
	return &invite, err
}

type InviteNew struct {
	Email string `json:"email"`
}

func NewInvite(email string) error {
	_, err := SendRequest(InviteNewRoute, Request{
		Data: &InviteNew{
			Email: email,
		},
	})
	return err
}