Skip to content

Commit

Permalink
minor changes were made
Browse files Browse the repository at this point in the history
  • Loading branch information
SadikSunbul committed Feb 7, 2025
1 parent f5ac8de commit 33325c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion email-verification/application/verification_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func NewVerificationService(
}

func (s *VerificationService) SendVerification(email string) error {
if email == "" {
return fmt.Errorf("email cannot be empty")
}

if _, err := s.repo.Get(email); err == nil {
return fmt.Errorf("verification already pending")
}

code, err := s.codeGen.Generate()
if err != nil {
return err
Expand All @@ -47,6 +55,10 @@ func (s *VerificationService) SendVerification(email string) error {
}

func (s *VerificationService) VerifyCode(email, code string) error {
if email == "" || code == "" {
return fmt.Errorf("email and code cannot be empty")
}

verification, err := s.repo.Get(email)
if err != nil {
return err
Expand All @@ -58,7 +70,9 @@ func (s *VerificationService) VerifyCode(email, code string) error {
}

if time.Now().After(verification.Exp) {
s.repo.Delete(email)
if err := s.repo.Delete(email); err != nil {
return fmt.Errorf("failed to delete expired code: %w", err)
}
return fmt.Errorf("code expired")
}

Expand Down
4 changes: 2 additions & 2 deletions email-verification/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func GetConfig() *Config {
return &Config{
SMTPHost: "smtp.gmail.com",
SMTPPort: 587,
SMTPUser: "your-email@gmail.com",
SMTPPassword: "your-app-password",
SMTPUser: "tahasfhga@gmail.com",
SMTPPassword: "bakkcmkakpfxwuef",
CodeExpiration: time.Minute * 1,
}
}

0 comments on commit 33325c6

Please sign in to comment.