@@ -16,7 +16,10 @@ type Manager interface {
|
||||
AddUser(user User) (User, error)
|
||||
GetUsers() ([]User, error)
|
||||
GetUserByEmail(email string) (User, error)
|
||||
UpdateVerificationTime(verifiedAt int64, email string) error
|
||||
AddVerification(verification Verification) (Verification, error)
|
||||
GetVerificationByToken(token string) (Verification, error)
|
||||
DeleteToken(email string) error
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
|
@@ -60,3 +60,13 @@ func (mgr *manager) GetUserByEmail(email string) (User, error) {
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (mgr *manager) UpdateVerificationTime(verifiedAt int64, email string) error {
|
||||
result := mgr.db.Model(&User{}).Where("email = ?", email).Update("email_verified_at", verifiedAt)
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type Verification struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Token string
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Token string `gorm:"index"`
|
||||
Identifier string
|
||||
ExpiresAt int64
|
||||
CreatedAt int64 `gorm:"autoCreateTime"`
|
||||
@@ -28,3 +28,27 @@ func (mgr *manager) AddVerification(verification Verification) (Verification, er
|
||||
}
|
||||
return verification, nil
|
||||
}
|
||||
|
||||
func (mgr *manager) GetVerificationByToken(token string) (Verification, error) {
|
||||
var verification Verification
|
||||
result := mgr.db.Where("token = ?", token).First(&verification)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`Error getting verification token:`, result.Error)
|
||||
return verification, result.Error
|
||||
}
|
||||
|
||||
return verification, nil
|
||||
}
|
||||
|
||||
func (mgr *manager) DeleteToken(email string) error {
|
||||
var verification Verification
|
||||
result := mgr.db.Where("email = ?", email).Delete(&verification)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`Error deleting token:`, result.Error)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user