forked from go-auth0/auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
79 lines (60 loc) · 2.51 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package management
type User struct {
// The users identifier.
ID string `json:"user_id,omitempty"`
// The connection the user belongs to.
Connection string `json:"connection"`
// The user's email
Email string `json:"email,omitempty"`
// The user's username. Only valid if the connection requires a username
Username string `json:"username,omitempty"`
// The user's password (mandatory for non SMS connections)
Password string `json:"password,omitempty"`
// The user's phone number (following the E.164 recommendation), only valid
// for users to be added to SMS connections.
PhoneNumber string `json:"phone_number,omitempty"`
// UserMetadata holds data that the user has read/write access to (e.g.
// color_preference, blog_url, etc).
UserMetadata map[string]interface{} `json:"user_metadata,omitempty"`
// True if the user's email is verified, false otherwise. If it is true then
// the user will not receive a verification email, unless verify_email: true
// was specified.
EmailVerified bool `json:"email_verified,omitempty"`
// If true, the user will receive a verification email after creation, even
// if created with email_verified set to true. If false, the user will not
// receive a verification email, even if created with email_verified set to
// false. If unspecified, defaults to the behavior determined by the value
// of email_verified.
VerifyEmail bool `json:"verify_email,omitempty"`
// True if the user's phone number is verified, false otherwise. When the
// user is added to a SMS connection, they will not receive an verification
// SMS if this is true.
PhoneVerified bool `json:"phone_verified,omitempty"`
// AppMetadata holds data that the user has read-only access to (e.g. roles,
// permissions, vip, etc).
AppMetadata map[string]interface{} `json:"app_metadata,omitempty"`
}
type UserManager struct {
m *Management
}
func NewUserManager(m *Management) *UserManager {
return &UserManager{m}
}
func (um *UserManager) Create(u *User) error {
return um.m.post(um.m.uri("users"), u)
}
func (um *UserManager) Read(id string, opts ...Option) (*User, error) {
u := new(User)
err := um.m.get(um.m.uri("users", id)+um.m.q(opts), u)
return u, err
}
func (um *UserManager) Update(id string, u *User) (err error) {
return um.m.patch(um.m.uri("users", id), u)
}
func (um *UserManager) Delete(id string) (err error) {
return um.m.delete(um.m.uri("users", id))
}
func (um *UserManager) List(opts ...Option) (us []*User, err error) {
err = um.m.get(um.m.uri("users")+um.m.q(opts), &us)
return
}