implemented verifiaction db

This commit is contained in:
Stephan D
2026-02-05 20:51:03 +01:00
parent 4639b2c610
commit f8a3bef2e6
12 changed files with 290 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
package model
import (
"time"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/mservice"
"go.mongodb.org/mongo-driver/v2/bson"
@@ -27,11 +29,10 @@ type AccountPublic struct {
}
type Account struct {
AccountPublic `bson:",inline" json:",inline"`
EmailBackup string `bson:"emailBackup" json:"emailBackup"`
Password string `bson:"password" json:"password"`
ResetPasswordToken string `bson:"resetPasswordToken" json:"resetPasswordToken"`
VerifyToken string `bson:"verifyToken" json:"verifyToken"`
AccountPublic `bson:",inline" json:",inline"`
EmailBackup string `bson:"emailBackup" json:"-"`
Password string `bson:"password" json:"-"` // password hash
EmailVerifiedAt *time.Time `bson:"emailVerifiedAt,omitempty" json:"-"`
}
func (a *Account) HashPassword() error {

View File

@@ -0,0 +1,30 @@
package model
import (
"time"
"github.com/tech/sendico/pkg/db/storable"
"go.mongodb.org/mongo-driver/v2/bson"
)
type VerificationPurpose string
const (
PurposeAccountActivation VerificationPurpose = "account_activation"
PurposeEmailChange VerificationPurpose = "email_change"
PurposePasswordReset VerificationPurpose = "password_reset"
PurposeSensitiveAction VerificationPurpose = "sensitive_action"
PurposeMagicLogin VerificationPurpose = "magic_login"
)
type VerificationToken struct {
storable.Base `bson:",inline" json:",inline"`
ArchivableBase `bson:",inline" json:",inline"`
Target string `bson:"target,omitempty" json:"target"`
AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"`
Purpose VerificationPurpose `bson:"purpose" json:"purpose"`
VerifyTokenHash string `bson:"verifyTokenHash" json:"-"`
UsedAt *time.Time `bson:"usedAt,omitempty" json:"-"`
ExpiresAt time.Time `bson:"expiresAt" json:"-"`
}