package web import ( "context" "errors" "strconv" "time" ) const AccountSessionsPerPage = 20 const BrowserLogoutPath = "/logout/browser" var ErrAccountNotFound = errors.New("web: no such session of this user") type AccountProblem int const ( AccountPasswordWrong AccountProblem = iota + 1 AccountPasswordShort AccountPasswordLong AccountBusy AccountDisplayNameInvalid AccountPasswordChanged ) var accountProblemNames = map[AccountProblem]string{ AccountPasswordWrong: "the current password is not correct", AccountPasswordShort: "the new password is too short", AccountPasswordLong: "the new password is too long", AccountBusy: "the password check is busy", AccountDisplayNameInvalid: "the display name is not valid", AccountPasswordChanged: "the password was changed in the meantime", } func (p AccountProblem) Error() string { if s, ok := accountProblemNames[p]; ok { return "web: account: " + s } return "web: unknown account problem " + strconv.Itoa(int(p)) } type AccountProfile struct { Username, DisplayName string Groups []string GroupCount int Primary string AdminURL string Google, Portdistrict bool GoogleLink *AccountGoogleLink SSHKeys []SSHKey } type AccountSession struct { ID, Host string Created, Expires time.Time ThisSession, ThisBrowser bool ClientID, Address string UserAgent string LastSeen time.Time } type AccountSessions struct { Sessions []AccountSession Total int } type AccountBackend interface { Profile(ctx context.Context, p Principal) (AccountProfile, error) ChangePassword(ctx context.Context, p Principal, current, next string) error Sessions(ctx context.Context, p Principal, page int) (AccountSessions, error) RevokeSession(ctx context.Context, p Principal, id string) error RevokeOtherSessions(ctx context.Context, p Principal) (int, error) SignOutBrowser(ctx context.Context, p Principal) (int, error) UpdateDisplayName(ctx context.Context, p Principal, name string) error SSHKeys(ctx context.Context, p Principal) ([]SSHKey, error) AddSSHKey(ctx context.Context, p Principal, key, label string) (SSHKey, error) RemoveSSHKey(ctx context.Context, p Principal, keyID string) (SSHKey, error) }