diff options
Diffstat (limited to 'app/models/user.go')
-rw-r--r-- | app/models/user.go | 63 |
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 @@ | |||
1 | package models | ||
2 | |||
3 | import ( | ||
4 | "context" | ||
5 | "time" | ||
6 | |||
7 | "github.com/go-webauthn/webauthn/webauthn" | ||
8 | ) | ||
9 | |||
10 | type User struct { | ||
11 | Username string `bson:"_id"` | ||
12 | DisplayName string | ||
13 | AllowedHosts []string | ||
14 | Fido2Credentials []webauthn.Credential | ||
15 | Deleted *time.Time | ||
16 | } | ||
17 | |||
18 | var _ webauthn.User = (*User)(nil) | ||
19 | |||
20 | func (u *User) RecordId() string { | ||
21 | return u.Username | ||
22 | } | ||
23 | |||
24 | func (u *User) MarkDeleted(t time.Time) { | ||
25 | u.Deleted = &t | ||
26 | } | ||
27 | |||
28 | func (u *User) WebAuthnID() []byte { | ||
29 | return []byte(u.Username) | ||
30 | } | ||
31 | |||
32 | func (u *User) WebAuthnName() string { | ||
33 | return u.Username | ||
34 | } | ||
35 | |||
36 | func (u *User) WebAuthnDisplayName() string { | ||
37 | return u.DisplayName | ||
38 | } | ||
39 | |||
40 | func (u *User) WebAuthnCredentials() []webauthn.Credential { | ||
41 | return u.Fido2Credentials | ||
42 | } | ||
43 | |||
44 | func (u *User) WebAuthnIcon() string { | ||
45 | return "" | ||
46 | } | ||
47 | |||
48 | func (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 | |||
57 | type 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 | } | ||