From 35c45a8126c71863caa76208a9c8e0669360464f Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Sun, 5 Feb 2023 19:00:47 +0530 Subject: [PATCH] send user email once registration is sent --- README.md | 2 +- examples/publapi.service | 3 +-- pages/signup.go | 13 +++++++++---- publapi.env | 3 +++ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 publapi.env diff --git a/README.md b/README.md index e9e8e90..40344fa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ go build By default publapi listens on 127.0.0.1:3000. You can change the port with the environment variable PUBLAPI_PORT. -Additionally, you need to set the variable PUBLAPI_SHOUTRRRURL in order for signup notifications to work. Url Format can be found at https://containrrr.dev/shoutrrr/v0.5/services/matrix/ +Additionally, you need to set the variable PUBLAPI_EMAIL_SHOUTRRRURL and PUBLAPI_NOTIFY_SHOUTRRRURL in order for signup notifications to work. URL Format can be found at https://containrrr.dev/shoutrrr/v0.5. ## Usage Currently, PublAPI has only two routes, /users and /signup. diff --git a/examples/publapi.service b/examples/publapi.service index 69b44c2..c9ae32f 100644 --- a/examples/publapi.service +++ b/examples/publapi.service @@ -5,8 +5,7 @@ After=networking.target WorkingDirectory=/var/publapi User=publapi Group=publapi -Environment=PUBLAPI_PORT=3000 -Environment=PUBLAPI_SHOUTRRRURL='matrix://user:password@host/' +EnvironmentFile=/var/publapi/publapi.env ExecStart=/var/publapi/publapi RestartSec=5 Restart=always diff --git a/pages/signup.go b/pages/signup.go index 705cd10..4122f19 100644 --- a/pages/signup.go +++ b/pages/signup.go @@ -2,11 +2,10 @@ package pages import ( "github.com/ProjectSegfault/publapi/utils" - "github.com/gofiber/fiber/v2" - "os" - "github.com/containrrr/shoutrrr" + "github.com/gofiber/fiber/v2" log "github.com/sirupsen/logrus" + "os" "strings" ) @@ -44,8 +43,14 @@ func SignupPage(c *fiber.Ctx) error { } log.Info("Registration request for " + username + " has been submitted by the frontend and has been written to /var/publapi/users/" + username + ".sh") + // send notification to user that their reg request was sent + err = shoutrrr.Send(os.Getenv("PUBLAPI_EMAIL_SHOUTRRRURL")+email, "Hello "+username+",\nYour registration request has been sent.\nIt will take a maximum of 48 hours for the request to be processed.\nThank you for being part of the Project Segfault Pubnix.") + if err != nil { + log.Error("Error sending email to user", err) + return c.SendStatus(fiber.StatusInternalServerError) + } // send notification to admins - err = shoutrrr.Send(os.Getenv("PUBLAPI_SHOUTRRRURL"), "New user signup! Please review /var/publapi/users/"+username+".sh to approve or deny the user. IP: "+ip+" Email: "+email) + err = shoutrrr.Send(os.Getenv("PUBLAPI_NOTIFY_SHOUTRRRURL"), "New user signup! Please review /var/publapi/users/"+username+".sh to approve or deny the user. IP: "+ip+" Email: "+email) if err != nil { log.Error("Error sending notification to admins", err) return c.SendStatus(fiber.StatusInternalServerError) diff --git a/publapi.env b/publapi.env new file mode 100644 index 0000000..927beee --- /dev/null +++ b/publapi.env @@ -0,0 +1,3 @@ +PUBLAPI_PORT=3000 +PUBLAPI_NOTIFY_SHOUTRRRURL='matrix://pubnixbot:xxx@projectsegfau.lt/' +PUBLAPI_EMAIL_SHOUTRRRURL='smtp://pubnix%40projectsegfau.lt:xxx@mail.projectsegfau.lt:587/?auth=Plain&fromaddress=pubnix%40projectsegfau.lt&fromname=Project+Segfault+Pubnix&subject=Your+registration+request+for+the+Project+Segfault+pubnix+has+been+sent&toaddresses='