Files
hanko/backend/persistence/models/webauthn_credential_user_handle.go
Frederic Jahn 21fd1d460f Feat custom user handle (#1978)
Add a custom user handle to a webauthn credential

---------

Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com>
2024-12-05 15:26:22 +01:00

29 lines
1.1 KiB
Go

package models
import (
"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gobuffalo/validate/v3/validators"
"github.com/gofrs/uuid"
"time"
)
type WebauthnCredentialUserHandle struct {
ID uuid.UUID `db:"id" json:"id"`
UserID uuid.UUID `db:"user_id" json:"user_id"`
Handle string `db:"handle" json:"handle"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
func (userHandle *WebauthnCredentialUserHandle) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.UUIDIsPresent{Name: "ID", Field: userHandle.ID},
&validators.UUIDIsPresent{Name: "UserId", Field: userHandle.UserID},
&validators.StringIsPresent{Name: "handle", Field: userHandle.Handle},
&validators.TimeIsPresent{Name: "CreatedAt", Field: userHandle.CreatedAt},
&validators.TimeIsPresent{Name: "UpdatedAt", Field: userHandle.UpdatedAt},
), nil
}