diff --git a/main.go b/main.go index bb036b6..fe2792f 100644 --- a/main.go +++ b/main.go @@ -336,6 +336,7 @@ func TranslateFilters(app *pocketbase.PocketBase, dataset string, filterGroups [ var app *pocketbase.PocketBase func main() { + const baseUrl = "https://pb.venbait.in" app = pocketbase.New() @@ -670,10 +671,23 @@ func main() { app.OnRecordAfterCreateRequest().Add(func(e *core.RecordCreateEvent) error { if e.Record.Collection().Name == "users" { // Retrieve user details - name := e.Record.GetString("username") + name := e.Record.GetString("uname") email := e.Record.GetString("email") userID := e.Record.Id // User ID + imageRecord, err := app.Dao().FindFirstRecordByData("images", "file_name", "app_logo") + if err != nil { + log.Printf("Failed to fetch logo from images collection: %v", err) + return nil + } + + // Construct the logo URL + logoURL := fmt.Sprintf("%s/api/files/images/%s/%s", + baseUrl, + imageRecord.Id, + imageRecord.GetString("file"), + ) + // Email subject subject := "Please Verify Your Email Address" @@ -690,9 +704,12 @@ func main() { Verify Email

If you did not register for this account, please ignore this email.

+
+

Best regards,

+ FCSC Logo - `, name, verificationURL) + `, name, verificationURL, logoURL) // Create the email message message := &mailer.Message{ @@ -711,7 +728,7 @@ func main() { } // Send the email - err := app.NewMailClient().Send(message) + err = app.NewMailClient().Send(message) if err != nil { log.Printf("Failed to send verification email to user: %v", err) return err @@ -1039,7 +1056,7 @@ func main() { return err } - userName := user.GetString("username") + userName := user.GetString("uname") // Extract and format the creation time createdTime := e.Record.Get("created").(types.DateTime) // Extract created time @@ -1055,6 +1072,19 @@ func main() { // Email subject subject := "UAE Stats Feedback" + imageRecord, err := app.Dao().FindFirstRecordByData("images", "file_name", "app_logo") + if err != nil { + log.Printf("Failed to fetch logo from images collection: %v", err) + return nil + } + + // Construct the logo URL + logoURL := fmt.Sprintf("%s/api/files/images/%s/%s", + baseUrl, + imageRecord.Id, + imageRecord.GetString("file"), + ) + // Email body in HTML format body := fmt.Sprintf(` @@ -1079,10 +1109,10 @@ func main() { 1. %s

Thank you,

-

The FCSC App Team

+ FCSC Logo - `, adminName, userName, formattedDate, formattedDateTime, emojiRating, easeOfUse, quality, design, redundancy, additionalFeedback) + `, adminName, userName, formattedDate, formattedDateTime, emojiRating, easeOfUse, quality, design, redundancy, additionalFeedback, logoURL) // Define the target type (e.g., "smtp") targetType := "feedback_receive_mail" @@ -1198,6 +1228,8 @@ func main() { } } +const baseUrl = "https://pb.venbait.in" + // generateOTP generates a random 4-digit OTP func generateOTP() (int, error) { max := big.NewInt(10000) // 4-digit numbers range: 0000 to 9999 @@ -1345,7 +1377,7 @@ func verifyEmailHandler(c echo.Context) error { `) // Fetch user details for email notification - username := record.GetString("username") + username := record.GetString("uname") userEmail := record.GetString("email") // Send admin email asynchronously @@ -1364,6 +1396,20 @@ func sendAdminEmail(app *pocketbase.PocketBase, userID, username, userEmail stri adminName := "Admin" subject := "New User Registration Pending Review" + // Fetch the image file URL from the PocketBase collection + imageRecord, err := app.Dao().FindFirstRecordByData("images", "file_name", "app_logo") + if err != nil { + log.Printf("Failed to fetch logo from images collection: %v", err) + return nil + } + + // Construct the logo URL + logoURL := fmt.Sprintf("%s/api/files/images/%s/%s", + baseUrl, + imageRecord.Id, + imageRecord.GetString("file"), + ) + body := fmt.Sprintf(` @@ -1377,9 +1423,11 @@ func sendAdminEmail(app *pocketbase.PocketBase, userID, username, userEmail stri Approve Reject

+

Thank you,

+ FCSC Logo - `, adminName, username, userEmail, userID, userID) + `, adminName, username, userEmail, userID, userID, logoURL) emailConfig, err := app.Dao().FindFirstRecordByData("email_configuration", "type", "admin_receive_mail") if err != nil { @@ -1412,12 +1460,25 @@ func sendAdminEmail(app *pocketbase.PocketBase, userID, username, userEmail stri func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, newStatus string) error { userEmail := record.GetString("email") - userName := record.GetString("username") + userName := record.GetString("uname") if userEmail == "" { return fmt.Errorf("user email is empty") } + imageRecord, err := app.Dao().FindFirstRecordByData("images", "file_name", "app_logo") + if err != nil { + log.Printf("Failed to fetch logo from images collection: %v", err) + return nil + } + + // Construct the logo URL + logoURL := fmt.Sprintf("%s/api/files/images/%s/%s", + baseUrl, + imageRecord.Id, + imageRecord.GetString("file"), + ) + var subject, body string if newStatus == "Approved" { @@ -1427,7 +1488,10 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne

We are pleased to inform you that your registration with FCSC has been approved. You can now log in using the credentials that you had created.

Please access your account using the following link: Login.

If you have any questions, please feel free to contact us for further clarification.

- `, userName) +
+

Best regards,

+ FCSC Logo + `, userName, logoURL) } else if newStatus == "Denied" { subject = "Registration Update – FCSC" body = fmt.Sprintf(` @@ -1435,8 +1499,10 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne

Thank you for registering with FCSC. After careful review, we regret to inform you that your registration has not been approved at this time.

If you have any questions or believe this decision was made in error, please feel free to contact us for further clarification.

We appreciate your understanding and thank you for your interest.

-

Best regards,

- `, userName) +
+

Best regards,

+ FCSC Logo + `, userName, logoURL) } else { // If the status is neither "Approved" nor "Denied", skip sending an email return nil @@ -1458,7 +1524,7 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne HTML: body, } - err := app.NewMailClient().Send(message) + err = app.NewMailClient().Send(message) if err != nil { return fmt.Errorf("failed to send email: %v", err) } diff --git a/pb_data/config.json b/pb_data/config.json index ad7082d..fdc6296 100644 --- a/pb_data/config.json +++ b/pb_data/config.json @@ -7,6 +7,9 @@ "tls": true, "fromAddress": "bbone@venbait.in", "fromName": "FCSC" + }, + "meta": { + "publicUrl": "https://pb.venbait.in" } } diff --git a/pb_data/logs.db b/pb_data/logs.db index ad90531..bfd14c7 100644 Binary files a/pb_data/logs.db and b/pb_data/logs.db differ