Add Apple Sign In welcome email, notification preferences on registration, and contractor sharing tests
- Send welcome email to new users who sign up via Apple Sign In - Create notification preferences (all enabled) when new accounts are created - Add comprehensive integration tests for contractor sharing: - Personal contractors only visible to creator - Residence-tied contractors visible to all users with residence access - Update/delete access control for shared contractors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -33,8 +33,9 @@ var (
|
||||
|
||||
// AuthService handles authentication business logic
|
||||
type AuthService struct {
|
||||
userRepo *repositories.UserRepository
|
||||
cfg *config.Config
|
||||
userRepo *repositories.UserRepository
|
||||
notificationRepo *repositories.NotificationRepository
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewAuthService creates a new auth service
|
||||
@@ -45,6 +46,11 @@ func NewAuthService(userRepo *repositories.UserRepository, cfg *config.Config) *
|
||||
}
|
||||
}
|
||||
|
||||
// SetNotificationRepository sets the notification repository for creating notification preferences
|
||||
func (s *AuthService) SetNotificationRepository(notificationRepo *repositories.NotificationRepository) {
|
||||
s.notificationRepo = notificationRepo
|
||||
}
|
||||
|
||||
// Login authenticates a user and returns a token
|
||||
func (s *AuthService) Login(req *requests.LoginRequest) (*responses.LoginResponse, error) {
|
||||
// Find user by username or email
|
||||
@@ -134,6 +140,14 @@ func (s *AuthService) Register(req *requests.RegisterRequest) (*responses.Regist
|
||||
fmt.Printf("Failed to create user profile: %v\n", err)
|
||||
}
|
||||
|
||||
// Create notification preferences with all options enabled
|
||||
if s.notificationRepo != nil {
|
||||
if _, err := s.notificationRepo.GetOrCreatePreferences(user.ID); err != nil {
|
||||
// Log error but don't fail registration
|
||||
fmt.Printf("Failed to create notification preferences: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create auth token
|
||||
token, err := s.userRepo.GetOrCreateToken(user.ID)
|
||||
if err != nil {
|
||||
@@ -523,6 +537,14 @@ func (s *AuthService) AppleSignIn(ctx context.Context, appleAuth *AppleAuthServi
|
||||
_ = s.userRepo.SetProfileVerified(user.ID, true)
|
||||
}
|
||||
|
||||
// Create notification preferences with all options enabled
|
||||
if s.notificationRepo != nil {
|
||||
if _, err := s.notificationRepo.GetOrCreatePreferences(user.ID); err != nil {
|
||||
// Log error but don't fail registration
|
||||
fmt.Printf("Failed to create notification preferences: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Link Apple ID
|
||||
appleAuthRecord := &models.AppleSocialAuth{
|
||||
UserID: user.ID,
|
||||
|
||||
@@ -198,6 +198,8 @@ func (s *ContractorService) UpdateContractor(contractorID, userID uint, req *req
|
||||
if req.IsFavorite != nil {
|
||||
contractor.IsFavorite = *req.IsFavorite
|
||||
}
|
||||
// If residence_id is not sent in the request (nil), it means the user
|
||||
// removed the residence association - contractor becomes personal
|
||||
contractor.ResidenceID = req.ResidenceID
|
||||
|
||||
if err := s.contractorRepo.Update(contractor); err != nil {
|
||||
|
||||
@@ -145,6 +145,76 @@ The Casera Team
|
||||
return s.SendEmail(to, subject, htmlBody, textBody)
|
||||
}
|
||||
|
||||
// SendAppleWelcomeEmail sends a welcome email for Apple Sign In users (no verification needed)
|
||||
func (s *EmailService) SendAppleWelcomeEmail(to, firstName string) error {
|
||||
subject := "Welcome to Casera!"
|
||||
|
||||
name := firstName
|
||||
if name == "" {
|
||||
name = "there"
|
||||
}
|
||||
|
||||
htmlBody := fmt.Sprintf(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; }
|
||||
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.header { text-align: center; padding: 20px 0; }
|
||||
.cta { background: #07A0C3; color: white; padding: 15px 30px; text-decoration: none; border-radius: 8px; display: inline-block; margin: 20px 0; }
|
||||
.features { background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0; }
|
||||
.feature { margin: 10px 0; }
|
||||
.footer { text-align: center; color: #666; font-size: 12px; margin-top: 40px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Welcome to Casera!</h1>
|
||||
</div>
|
||||
<p>Hi %s,</p>
|
||||
<p>Thank you for joining Casera! Your account has been created and you're ready to start managing your properties.</p>
|
||||
<div class="features">
|
||||
<h3>Here's what you can do with Casera:</h3>
|
||||
<div class="feature">🏠 <strong>Manage Properties</strong> - Track all your homes and rentals in one place</div>
|
||||
<div class="feature">✅ <strong>Task Management</strong> - Never miss maintenance with smart scheduling</div>
|
||||
<div class="feature">👷 <strong>Contractor Directory</strong> - Keep your trusted pros organized</div>
|
||||
<div class="feature">📄 <strong>Document Storage</strong> - Store warranties, manuals, and important records</div>
|
||||
</div>
|
||||
<p>If you have any questions, feel free to reach out to us at support@casera.app.</p>
|
||||
<p>Best regards,<br>The Casera Team</p>
|
||||
<div class="footer">
|
||||
<p>© %d Casera. All rights reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`, name, time.Now().Year())
|
||||
|
||||
textBody := fmt.Sprintf(`
|
||||
Welcome to Casera!
|
||||
|
||||
Hi %s,
|
||||
|
||||
Thank you for joining Casera! Your account has been created and you're ready to start managing your properties.
|
||||
|
||||
Here's what you can do with Casera:
|
||||
- Manage Properties: Track all your homes and rentals in one place
|
||||
- Task Management: Never miss maintenance with smart scheduling
|
||||
- Contractor Directory: Keep your trusted pros organized
|
||||
- Document Storage: Store warranties, manuals, and important records
|
||||
|
||||
If you have any questions, feel free to reach out to us at support@casera.app.
|
||||
|
||||
Best regards,
|
||||
The Casera Team
|
||||
`, name)
|
||||
|
||||
return s.SendEmail(to, subject, htmlBody, textBody)
|
||||
}
|
||||
|
||||
// SendVerificationEmail sends an email verification code
|
||||
func (s *EmailService) SendVerificationEmail(to, firstName, code string) error {
|
||||
subject := "Casera - Verify Your Email"
|
||||
|
||||
Reference in New Issue
Block a user