 3d9de8ba11
			
		
	
	
		3d9de8ba11
		
	
	
	
	
		
			
			- 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
		
			
				
	
	
		
			34 lines
		
	
	
	
		
			776 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			776 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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))
 | |
| }
 |