refactor: update SendEmailVerification to take a user id and look it up

This commit is contained in:
Derrick Hammer 2024-03-26 15:00:29 -04:00
parent 6d12ef9b94
commit 98c576e2e8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 3 deletions

View File

@ -116,7 +116,7 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver
} }
if verifyEmail { if verifyEmail {
err = s.SendEmailVerification(&user) err = s.SendEmailVerification(user.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -125,7 +125,12 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver
return &user, nil return &user, nil
} }
func (s *AccountServiceDefault) SendEmailVerification(user *models.User) error { func (s AccountServiceDefault) SendEmailVerification(userId uint) error {
exists, user, err := s.AccountExists(userId)
if !exists || err != nil {
return err
}
token := GenerateSecurityToken() token := GenerateSecurityToken()
var verification models.EmailVerification var verification models.EmailVerification
@ -134,7 +139,7 @@ func (s *AccountServiceDefault) SendEmailVerification(user *models.User) error {
verification.Token = token verification.Token = token
verification.ExpiresAt = time.Now().Add(time.Hour) verification.ExpiresAt = time.Now().Add(time.Hour)
err := s.db.Create(&verification).Error err = s.db.Create(&verification).Error
if err != nil { if err != nil {
return NewAccountError(ErrKeyDatabaseOperationFailed, err) return NewAccountError(ErrKeyDatabaseOperationFailed, err)
} }