feat: trusted devices and 'remember me' (#1982)

This commit is contained in:
bjoern-m
2024-11-29 11:06:47 +01:00
committed by GitHub
parent 298fa19423
commit f32f48e85b
41 changed files with 686 additions and 17 deletions

View File

@ -0,0 +1,30 @@
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 TrustedDevice struct {
ID uuid.UUID `db:"id"`
UserID uuid.UUID `db:"user_id"`
DeviceToken string `db:"device_token"`
ExpiresAt time.Time `db:"expires_at"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
func (trustedDevice *TrustedDevice) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.UUIDIsPresent{Name: "ID", Field: trustedDevice.ID},
&validators.UUIDIsPresent{Name: "UserID", Field: trustedDevice.UserID},
&validators.StringIsPresent{Name: "DeviceToken", Field: trustedDevice.DeviceToken},
&validators.StringLengthInRange{Name: "DeviceToken", Field: trustedDevice.DeviceToken, Min: 64, Max: 128},
&validators.TimeIsPresent{Name: "ExpiresAt", Field: trustedDevice.ExpiresAt},
&validators.TimeIsPresent{Name: "UpdatedAt", Field: trustedDevice.UpdatedAt},
&validators.TimeIsPresent{Name: "CreatedAt", Field: trustedDevice.CreatedAt},
), nil
}