1package web
2
3import (
4 "context"
5 "errors"
6 "strconv"
7 "time"
8)
9
10const AccountSessionsPerPage = 20
11
12const BrowserLogoutPath = "/logout/browser"
13
14var ErrAccountNotFound = errors.New("web: no such session of this user")
15
16type AccountProblem int
17
18const (
19 AccountPasswordWrong AccountProblem = iota + 1
20 AccountPasswordShort
21 AccountPasswordLong
22 AccountBusy
23 AccountDisplayNameInvalid
24 AccountPasswordChanged
25)
26
27var accountProblemNames = map[AccountProblem]string{
28 AccountPasswordWrong: "the current password is not correct",
29 AccountPasswordShort: "the new password is too short",
30 AccountPasswordLong: "the new password is too long",
31 AccountBusy: "the password check is busy",
32 AccountDisplayNameInvalid: "the display name is not valid",
33 AccountPasswordChanged: "the password was changed in the meantime",
34}
35
36func (p AccountProblem) Error() string {
37 if s, ok := accountProblemNames[p]; ok {
38 return "web: account: " + s
39 }
40 return "web: unknown account problem " + strconv.Itoa(int(p))
41}
42
43type AccountProfile struct {
44 Username, DisplayName string
45 Groups []string
46 GroupCount int
47 Primary string
48 AdminURL string
49 Google, Portdistrict bool
50 GoogleLink *AccountGoogleLink
51 SSHKeys []SSHKey
52}
53
54type AccountSession struct {
55 ID, Host string
56 Created, Expires time.Time
57 ThisSession, ThisBrowser bool
58 ClientID, Address string
59 UserAgent string
60 LastSeen time.Time
61}
62
63type AccountSessions struct {
64 Sessions []AccountSession
65 Total int
66}
67
68type AccountBackend interface {
69 Profile(ctx context.Context, p Principal) (AccountProfile, error)
70 ChangePassword(ctx context.Context, p Principal, current, next string) error
71 Sessions(ctx context.Context, p Principal, page int) (AccountSessions, error)
72 RevokeSession(ctx context.Context, p Principal, id string) error
73 RevokeOtherSessions(ctx context.Context, p Principal) (int, error)
74 SignOutBrowser(ctx context.Context, p Principal) (int, error)
75 UpdateDisplayName(ctx context.Context, p Principal, name string) error
76 SSHKeys(ctx context.Context, p Principal) ([]SSHKey, error)
77 AddSSHKey(ctx context.Context, p Principal, key, label string) (SSHKey, error)
78 RemoveSSHKey(ctx context.Context, p Principal, keyID string) (SSHKey, error)
79}