From 98c576e2e84367cb0e80948fb1fcf753f32bcbe6 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 26 Mar 2024 15:00:29 -0400 Subject: [PATCH] refactor: update SendEmailVerification to take a user id and look it up --- account/account.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/account/account.go b/account/account.go index bd06131..57c4f7e 100644 --- a/account/account.go +++ b/account/account.go @@ -116,7 +116,7 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver } if verifyEmail { - err = s.SendEmailVerification(&user) + err = s.SendEmailVerification(user.ID) if err != nil { return nil, err } @@ -125,7 +125,12 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver 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() var verification models.EmailVerification @@ -134,7 +139,7 @@ func (s *AccountServiceDefault) SendEmailVerification(user *models.User) error { verification.Token = token verification.ExpiresAt = time.Now().Add(time.Hour) - err := s.db.Create(&verification).Error + err = s.db.Create(&verification).Error if err != nil { return NewAccountError(ErrKeyDatabaseOperationFailed, err) }