add middlewares, handlers and database models
This commit is contained in:
parent
979a415b95
commit
7e288ea67a
24 changed files with 1045 additions and 14 deletions
23
internal/model/file.go
Normal file
23
internal/model/file.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
FileTypeAvatar = "avatar"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
ID string `db:"id"`
|
||||
UserID string `db:"user_id"` // Who owns/created this file
|
||||
OwnerType string `db:"owner_type"` // "user", "profile", etc. - the entity that owns the file
|
||||
OwnerID string `db:"owner_id"` // Polymorphic FK
|
||||
Type string `db:"type"`
|
||||
Filename string `db:"filename"`
|
||||
OriginalName string `db:"original_name"`
|
||||
MimeType string `db:"mime_type"`
|
||||
Size int64 `db:"size"`
|
||||
StoragePath string `db:"storage_path"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
11
internal/model/profile.go
Normal file
11
internal/model/profile.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Profile struct {
|
||||
ID string `db:"id"`
|
||||
UserID string `db:"user_id"`
|
||||
Name string `db:"name"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
34
internal/model/token.go
Normal file
34
internal/model/token.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
ID string `db:"id"`
|
||||
UserID string `db:"user_id"`
|
||||
Type string `db:"type"` // "email_verify" or "password_reset"
|
||||
Token string `db:"token"`
|
||||
ExpiresAt time.Time `db:"expires_at"`
|
||||
UsedAt *time.Time `db:"used_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
|
||||
const (
|
||||
TokenTypeEmailVerify = "email_verify"
|
||||
TokenTypePasswordReset = "password_reset"
|
||||
TokenTypeEmailChange = "email_change"
|
||||
TokenTypeMagicLink = "magic_link"
|
||||
)
|
||||
|
||||
func (t *Token) IsExpired() bool {
|
||||
return time.Now().After(t.ExpiresAt)
|
||||
}
|
||||
|
||||
func (t *Token) IsUsed() bool {
|
||||
return t.UsedAt != nil
|
||||
}
|
||||
|
||||
func (t *Token) IsValid() bool {
|
||||
return !t.IsExpired() && !t.IsUsed()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue