feat: add user service layer with business logic

- Create services/user_service.go with user creation and verification
- Add input validation for username, email, and password
- Implement duplicate user checking and password hashing
- Add comprehensive error handling and logging
This commit is contained in:
Cipher Vance 2025-09-18 20:06:36 -05:00
parent 3ed698918b
commit 3d9de8ba11
3 changed files with 107 additions and 60 deletions

34
services/email_service.go Normal file
View file

@ -0,0 +1,34 @@
package services
import (
"fmt"
"net/smtp"
"os"
)
type EmailService struct {
smtpHost string
smtpPort string
smtpUser string
smtpPassword string
}
func NewEmailService() *EmailService {
return &EmailService{
smtpHost: os.Getenv("SMTP_SERVER"),
smtpPort: os.Getenv("SMTP_PORT"),
smtpUser: os.Getenv("SMTP_USER"),
smtpPassword: os.Getenv("SMTP_PASSWORD"),
}
}
func (e *EmailService) SendEmail(to, subject, body string) error {
from := e.smtpUser
msg := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s", from, to, subject, body)
auth := smtp.PlainAuth("", e.smtpUser, e.smtpPassword, e.smtpHost)
addr := fmt.Sprintf("%s:%s", e.smtpHost, e.smtpPort)
return smtp.SendMail(addr, auth, from, []string{to}, []byte(msg))
}