Skip to content

Commit

Permalink
send email for forgot password
Browse files Browse the repository at this point in the history
  • Loading branch information
bkawk committed Feb 5, 2023
1 parent 72d9f16 commit 36e1bc3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api/handlers/forgotPassword.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package handlers

import (
"bkawk/go-echo/api/emails"
"bkawk/go-echo/api/models"
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -42,8 +44,17 @@ func ForgotPasswordPost(c echo.Context) error {
return echo.NewHTTPError(http.StatusTooManyRequests, fmt.Sprintf("Try again in %d minutes and %d seconds", int(waitTime.Minutes()), int(waitTime.Seconds())%60))
}

// send email logic
fmt.Println("Sending forgot password email to", u.Email)
// Get the verification URL from the environment
resetEmailUrl := os.Getenv("RESET_EMAIL_URL")
if resetEmailUrl == "" {
return fmt.Errorf("environment variable not set: VERIFY_URL")
}
// Send welcome email
emailError := emails.SendResetPasswordEmail(u.Email, resetEmailUrl+"?verificationCode="+u.VerificationCode)
if emailError != nil {
fmt.Println(emailError)
return c.JSON(http.StatusInternalServerError, echo.Map{"error": emailError})
}

user.ForgotPassword = time.Now().Unix()
if _, err := collection.ReplaceOne(ctx, filter, user); err != nil {
Expand Down

0 comments on commit 36e1bc3

Please sign in to comment.