feat: add password reset, account verification models, and a verified field to users

This commit is contained in:
Derrick Hammer 2024-02-26 07:47:05 -05:00
parent 3da1ae3e5f
commit 1be4fb47fc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 52 additions and 14 deletions

View File

@ -65,6 +65,8 @@ func NewDatabase(lc fx.Lifecycle, params DatabaseParams) *gorm.DB {
&models.Blocklist{},
&models.DNSLink{},
&models.Download{},
&models.EmailVerification{},
&models.PasswordReset{},
&models.Pin{},
&models.PublicKey{},
&models.Upload{},

View File

@ -0,0 +1,17 @@
package models
import (
"time"
"gorm.io/gorm"
)
type EmailVerification struct {
gorm.Model
UserID uint
User User
NewEmail string
Token string
ExpiresAt time.Time
}

View File

@ -0,0 +1,16 @@
package models
import (
"time"
"gorm.io/gorm"
)
type PasswordReset struct {
gorm.Model
UserID uint
User User
Token string
ExpiresAt time.Time
}

View File

@ -10,20 +10,23 @@ import (
type User struct {
gorm.Model
FirstName string
LastName string
Email string `gorm:"unique"`
PasswordHash string
Role string
PublicKeys []PublicKey
APIKeys []APIKey
Uploads []Upload
LastLogin *time.Time
LastLoginIP string
OTPEnabled bool `gorm:"default:false;"`
OTPVerified bool `gorm:"default:false;"`
OTPSecret string
OTPAuthUrl string
FirstName string
LastName string
Email string `gorm:"unique"`
PasswordHash string
Role string
PublicKeys []PublicKey
APIKeys []APIKey
Uploads []Upload
LastLogin *time.Time
LastLoginIP string
OTPEnabled bool `gorm:"default:false;"`
OTPVerified bool `gorm:"default:false;"`
OTPSecret string
OTPAuthUrl string
Verified bool `gorm:"default:false;"`
EmailVerifications []EmailVerification
PasswordResets []PasswordReset
}
func (u *User) BeforeUpdate(tx *gorm.DB) error {