fixing the password reset link

This commit is contained in:
Cipher Vance
2025-11-22 23:54:49 -06:00
parent 2a632ea833
commit 83630ab176

View File

@@ -4,6 +4,8 @@ import (
"crypto/rand" "crypto/rand"
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt"
"os"
"regexp" "regexp"
"time" "time"
@@ -77,7 +79,6 @@ func (s *Service) VerifyUser(username, password string) (*User, error) {
func (s *Service) RequestPasswordReset(email string) error { func (s *Service) RequestPasswordReset(email string) error {
user, err := s.repo.GetUserByEmail(email) user, err := s.repo.GetUserByEmail(email)
if err != nil { if err != nil {
// Don't leak if email exists
return nil return nil
} }
@@ -96,7 +97,12 @@ func (s *Service) RequestPasswordReset(email string) error {
return err return err
} }
resetLink := "https://rideaware.app/reset-password?token=" + token appURL := os.Getenv("APP_URL")
if appURL == "" {
appURL = "https://dev.rideaware.org"
}
resetLink := fmt.Sprintf("%s/reset-password?token=%s", appURL, token)
return s.email.SendPasswordResetEmail(user.Email, user.Username, resetLink) return s.email.SendPasswordResetEmail(user.Email, user.Username, resetLink)
} }
@@ -144,17 +150,14 @@ func (s *Service) ResetPassword(token, newPassword string) error {
return tx.Commit().Error return tx.Commit().Error
} }
// GetUserByID retrieves a user with their profile
func (s *Service) GetUserByID(userID uint) (*User, error) { func (s *Service) GetUserByID(userID uint) (*User, error) {
return s.repo.GetUserByID(userID) return s.repo.GetUserByID(userID)
} }
// UpdateUser saves user changes
func (s *Service) UpdateUser(user *User) error { func (s *Service) UpdateUser(user *User) error {
return s.repo.UpdateUser(user) return s.repo.UpdateUser(user)
} }
// Helper functions
func isValidEmail(email string) bool { func isValidEmail(email string) bool {
regex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`) regex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
return regex.MatchString(email) return regex.MatchString(email)