-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
78 lines (64 loc) · 2.63 KB
/
users.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
// Package users provides a users service definition.
package users
import (
"context"
)
// Service for users.
type Service interface {
// Get fetches the specified user.
Get(ctx context.Context, user UserSpec) (User, error)
// GetAuthenticatedSpec fetches the currently authenticated
// user specification, or UserSpec{ID: 0} if there is no
// authenticated user. A non-nil error is returned if the
// the authentication process was not able to successfully
// determine if a user or no user is currently authenticated.
GetAuthenticatedSpec(ctx context.Context) (UserSpec, error)
// GetAuthenticated fetches the currently authenticated user,
// or User{UserSpec: UserSpec{ID: 0}} if there is no authenticated user.
GetAuthenticated(ctx context.Context) (User, error)
// Edit the authenticated user.
Edit(ctx context.Context, er EditRequest) (User, error)
}
// Store for users.
type Store interface {
// Create creates the specified user.
// UserSpec must specify a valid (i.e., non-zero) user.
// It returns os.ErrExist if the user already exists.
Create(ctx context.Context, user User) error
// Get fetches the specified user.
Get(ctx context.Context, user UserSpec) (User, error)
}
// UserSpec specifies a user.
// ID value 0 represents no user. Valid users may not use 0 as their ID.
type UserSpec struct {
ID uint64
Domain string
}
// THINK: (2016-03-06) Consider merging Elsewhere with root-most UserSpec.
// Maybe even use a set, order of linked accounts shouldn't matter, should it?
//
// (2020-01-12) I'm not ready to commit to supporting multiple linked identities,
// so for now I'm documenting that Elsewhere is metadata only and not used for
// user equivalence or authentication purposes. But will keep thinking about this.
// User represents a user.
type User struct {
// UserSpec is the primary user identity. It is mostly used for user equivalence,
// and potentially for authentication for well-known domains (e.g., "github.com").
UserSpec
// CanonicalMe is an optional canonical user profile URL. When a non-zero value,
// it is used for identifying users that authenticate via the IndieAuth protocol.
CanonicalMe string
// Elsewhere represents alternative user identities. This information is not used for
// user equivalence or authentication purposes, but can be used for display purposes.
Elsewhere []UserSpec
Login string
Name string
Email string // Public email.
AvatarURL string
HTMLURL string
SiteAdmin bool
}
// EditRequest represents a request to edit a user.
type EditRequest struct {
// Currently nothing, but editable fields will be added here in the future.
}