feat(API): user invitations and emails

This commit is contained in:
fsylvain committed 2026-09-29 07:15:17 +02:00
1 parent 7aae704d0a
commit acdef18b37
17 files changed
+1687 -7

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
package invite
import (
"errors"
"time"
)
var ErrEmailHasAccount = errors.New("email already has an account")
var ErrPendingInvite = errors.New("pending invite already exists")
var ErrInviteNotFound = errors.New("invite not found")
var ErrInviteEmailNotSent = errors.New("invite email not sent")
const Lifetime = 3 * 24 * time.Hour
type Status string
const (
StatusPending Status = "pending"
StatusExpired Status = "expired"
StatusAccepted Status = "accepted"
)
type Invite struct {
ID uint32 `json:"id"`
Email string `json:"email"`
HashedCode string `json:"hashed_code"`
ExpiresAt time.Time `json:"expires_at"`
InvitedBy uint32 `json:"invited_by"`
AcceptedAt *time.Time `json:"accepted_at"`
CreatedAt time.Time `json:"created_at"`
}
func (i Invite) StatusAt(now time.Time) Status {
if i.AcceptedAt != nil {
return StatusAccepted
}
if i.ExpiresAt.After(now) {
return StatusPending
}
return StatusExpired
}