logo and username change
This commit is contained in:
parent
285d2051f1
commit
e008e66a51
92
main.go
92
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() {
|
||||
<a href="%s" style="padding: 10px 15px; background-color: blue; color: white; text-decoration: none; border-radius: 5px;">Verify Email</a>
|
||||
</p>
|
||||
<p>If you did not register for this account, please ignore this email.</p>
|
||||
</br>
|
||||
<p>Best regards,</p>
|
||||
<img src="%s" alt="FCSC Logo" style="width:150px; height:auto;">
|
||||
</body>
|
||||
</html>
|
||||
`, 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(`
|
||||
<html>
|
||||
@ -1079,10 +1109,10 @@ func main() {
|
||||
1. %s
|
||||
</pre>
|
||||
<p>Thank you,</p>
|
||||
<p>The FCSC App Team</p>
|
||||
<img src="%s" alt="FCSC Logo" style="width:150px; height:auto;">
|
||||
</body>
|
||||
</html>
|
||||
`, 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(`
|
||||
<html>
|
||||
<body>
|
||||
@ -1377,9 +1423,11 @@ func sendAdminEmail(app *pocketbase.PocketBase, userID, username, userEmail stri
|
||||
<a href="https://pb.venbait.in/api/custom/approve?userId=%s" style="padding: 10px 15px; background-color: green; color: white; text-decoration: none; border-radius: 5px;">Approve</a>
|
||||
<a href="https://pb.venbait.in/api/custom/reject?userId=%s" style="padding: 10px 15px; background-color: red; color: white; text-decoration: none; border-radius: 5px;">Reject</a>
|
||||
</p>
|
||||
<p>Thank you,</p>
|
||||
<img src="%s" alt="FCSC Logo" style="width:150px; height:auto;">
|
||||
</body>
|
||||
</html>
|
||||
`, 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
|
||||
<p>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.</p>
|
||||
<p>Please access your account using the following link: <a href="http://your-login-url.com">Login</a>.</p>
|
||||
<p>If you have any questions, please feel free to contact us for further clarification.</p>
|
||||
`, userName)
|
||||
</br>
|
||||
<p>Best regards,</p>
|
||||
<img src="%s" alt="FCSC Logo" style="width:150px; height:auto;">
|
||||
`, 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
|
||||
<p>Thank you for registering with FCSC. After careful review, we regret to inform you that your registration has not been approved at this time.</p>
|
||||
<p>If you have any questions or believe this decision was made in error, please feel free to contact us for further clarification.</p>
|
||||
<p>We appreciate your understanding and thank you for your interest.</p>
|
||||
<p>Best regards,</p>
|
||||
`, userName)
|
||||
</br>
|
||||
<p>Best regards,</p>
|
||||
<img src="%s" alt="FCSC Logo" style="width:150px; height:auto;">
|
||||
`, 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)
|
||||
}
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
"tls": true,
|
||||
"fromAddress": "bbone@venbait.in",
|
||||
"fromName": "FCSC"
|
||||
},
|
||||
"meta": {
|
||||
"publicUrl": "https://pb.venbait.in"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user