summaryrefslogtreecommitdiff
path: root/app/models/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/user.go')
-rw-r--r--app/models/user.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/models/user.go b/app/models/user.go
new file mode 100644
index 0000000..5c9ec90
--- /dev/null
+++ b/app/models/user.go
@@ -0,0 +1,63 @@
1package models
2
3import (
4 "context"
5 "time"
6
7 "github.com/go-webauthn/webauthn/webauthn"
8)
9
10type User struct {
11 Username string `bson:"_id"`
12 DisplayName string
13 AllowedHosts []string
14 Fido2Credentials []webauthn.Credential
15 Deleted *time.Time
16}
17
18var _ webauthn.User = (*User)(nil)
19
20func (u *User) RecordId() string {
21 return u.Username
22}
23
24func (u *User) MarkDeleted(t time.Time) {
25 u.Deleted = &t
26}
27
28func (u *User) WebAuthnID() []byte {
29 return []byte(u.Username)
30}
31
32func (u *User) WebAuthnName() string {
33 return u.Username
34}
35
36func (u *User) WebAuthnDisplayName() string {
37 return u.DisplayName
38}
39
40func (u *User) WebAuthnCredentials() []webauthn.Credential {
41 return u.Fido2Credentials
42}
43
44func (u *User) WebAuthnIcon() string {
45 return ""
46}
47
48func (u *User) AuthorizedForHost(host string) bool {
49 for _, c := range u.AllowedHosts {
50 if host == c {
51 return true
52 }
53 }
54 return false
55}
56
57type UserStore interface {
58 List(ctx context.Context) ([]*User, error)
59 ListAll(ctx context.Context) ([]*User, error)
60 Get(ctx context.Context, name string) (*User, error)
61 Upsert(ctx context.Context, m *User) error
62 Delete(ctx context.Context, m *User) error
63}