2024-08-12 11:00:25 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-webauthn/webauthn/protocol"
|
|
|
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
2024-10-23 10:02:11 +02:00
|
|
|
"github.com/stonith404/pocket-id/backend/internal/model/types"
|
2024-08-12 11:00:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2025-01-11 20:14:12 +01:00
|
|
|
Username string `sortable:"true"`
|
|
|
|
|
Email string `sortable:"true"`
|
|
|
|
|
FirstName string `sortable:"true"`
|
|
|
|
|
LastName string `sortable:"true"`
|
|
|
|
|
IsAdmin bool `sortable:"true"`
|
2025-01-19 06:02:07 -06:00
|
|
|
LdapID *string
|
2024-08-12 11:00:25 +02:00
|
|
|
|
2024-10-28 18:11:54 +01:00
|
|
|
CustomClaims []CustomClaim
|
|
|
|
|
UserGroups []UserGroup `gorm:"many2many:user_groups_users;"`
|
|
|
|
|
Credentials []WebauthnCredential
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnID() []byte { return []byte(u.ID) }
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnName() string { return u.Username }
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnDisplayName() string { return u.FirstName + " " + u.LastName }
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnIcon() string { return "" }
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnCredentials() []webauthn.Credential {
|
|
|
|
|
credentials := make([]webauthn.Credential, len(u.Credentials))
|
|
|
|
|
|
|
|
|
|
for i, credential := range u.Credentials {
|
|
|
|
|
credentials[i] = webauthn.Credential{
|
2024-12-12 17:21:28 +01:00
|
|
|
ID: credential.CredentialID,
|
2024-08-12 11:00:25 +02:00
|
|
|
AttestationType: credential.AttestationType,
|
|
|
|
|
PublicKey: credential.PublicKey,
|
|
|
|
|
Transport: credential.Transport,
|
2024-08-13 23:19:36 +02:00
|
|
|
Flags: webauthn.CredentialFlags{
|
|
|
|
|
BackupState: credential.BackupState,
|
|
|
|
|
BackupEligible: credential.BackupEligible,
|
|
|
|
|
},
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return credentials
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u User) WebAuthnCredentialDescriptors() (descriptors []protocol.CredentialDescriptor) {
|
|
|
|
|
credentials := u.WebAuthnCredentials()
|
|
|
|
|
|
|
|
|
|
descriptors = make([]protocol.CredentialDescriptor, len(credentials))
|
|
|
|
|
|
|
|
|
|
for i, credential := range credentials {
|
|
|
|
|
descriptors[i] = credential.Descriptor()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return descriptors
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 18:24:01 +01:00
|
|
|
func (u User) FullName() string { return u.FirstName + " " + u.LastName }
|
|
|
|
|
|
2024-08-12 11:00:25 +02:00
|
|
|
type OneTimeAccessToken struct {
|
|
|
|
|
Base
|
2024-08-23 17:04:19 +02:00
|
|
|
Token string
|
2024-10-23 10:02:11 +02:00
|
|
|
ExpiresAt datatype.DateTime
|
2024-08-12 11:00:25 +02:00
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
UserID string
|
2024-08-12 11:00:25 +02:00
|
|
|
User User
|
|
|
|
|
}
|