started Wix integrations
parent
4cbca250f6
commit
e4d1fb072a
|
|
@ -3,6 +3,9 @@ package controllers
|
|||
import (
|
||||
"api/database"
|
||||
"api/models"
|
||||
"api/services"
|
||||
"api/utils"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
|
@ -22,3 +25,23 @@ func GetGroups(c *fiber.Ctx) error {
|
|||
|
||||
return c.JSON(groups)
|
||||
}
|
||||
|
||||
func CreateUser(c *fiber.Ctx) error {
|
||||
var body map[string]interface{}
|
||||
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return fiber.ErrBadRequest
|
||||
}
|
||||
|
||||
email := body["email"].(string)
|
||||
|
||||
user := services.GetUserByEmail(email)
|
||||
|
||||
if user.ID == 0 {
|
||||
fmt.Println("inexistent user")
|
||||
}
|
||||
|
||||
utils.SendEmail(email)
|
||||
|
||||
return c.JSON(user)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,56 +126,64 @@ func OnPubStop(c *fiber.Ctx) error {
|
|||
return c.SendString("On_Pub_Stop: " + string(c.Body()))
|
||||
}
|
||||
|
||||
// func WixIntegration(c *fiber.Ctx) error {
|
||||
// var data models.Purchase
|
||||
func WixTest(c *fiber.Ctx) error {
|
||||
log.Println(string(c.Body()))
|
||||
return c.SendString("On Test: " + string(c.Body()))
|
||||
}
|
||||
|
||||
// if err := c.BodyParser(&data); err != nil {
|
||||
// return fiber.ErrBadRequest
|
||||
// }
|
||||
func WixIntegration(c *fiber.Ctx) error {
|
||||
log.Println(string(c.Body()))
|
||||
return c.SendString("On Integration: " + string(c.Body()))
|
||||
|
||||
// fmt.Println(data.Data.Contact.Email)
|
||||
// fmt.Println(data.Data.Contact.Name.First + " " + data.Data.Contact.Name.Last)
|
||||
// fmt.Printf("%s", data.Data.PlanOrderID)
|
||||
// fmt.Println(data.Data.PlanPrice.Value)
|
||||
// fmt.Println(data.Data.PlanStartDate)
|
||||
// fmt.Println(data.Data.PlanValidUntil)
|
||||
// fmt.Println(data.Data.PlanTitle)
|
||||
// var data models.Purchase
|
||||
|
||||
// var user models.User
|
||||
// if err := c.BodyParser(&data); err != nil {
|
||||
// return fiber.ErrBadRequest
|
||||
// }
|
||||
|
||||
// result := database.DB.Debug().Where("email = ?", data.Data.Contact.Email).First(&user)
|
||||
// fmt.Println(data.Data.Contact.Email)
|
||||
// fmt.Println(data.Data.Contact.Name.First + " " + data.Data.Contact.Name.Last)
|
||||
// fmt.Printf("%s", data.Data.PlanOrderID)
|
||||
// fmt.Println(data.Data.PlanPrice.Value)
|
||||
// fmt.Println(data.Data.PlanStartDate)
|
||||
// fmt.Println(data.Data.PlanValidUntil)
|
||||
// fmt.Println(data.Data.PlanTitle)
|
||||
|
||||
// if result.RowsAffected == 0 {
|
||||
// // User does not exist. Inserts it.
|
||||
// user := models.User{
|
||||
// Email: data.Data.Contact.Email,
|
||||
// Name: data.Data.Contact.Name.First + " " + data.Data.Contact.Name.Last,
|
||||
// Blocked: "N",
|
||||
// Cancelled: "N",
|
||||
// }
|
||||
// var user models.SystemUser
|
||||
|
||||
// database.DB.Debug().Create(&user)
|
||||
// }
|
||||
// result := database.DB.Debug().Where("email = ?", data.Data.Contact.Email).First(&user)
|
||||
|
||||
// value, err := strconv.ParseFloat(data.Data.PlanPrice.Value, 32)
|
||||
// if result.RowsAffected == 0 {
|
||||
// // User does not exist. Inserts it.
|
||||
// user := models.User{
|
||||
// Email: data.Data.Contact.Email,
|
||||
// Name: data.Data.Contact.Name.First + " " + data.Data.Contact.Name.Last,
|
||||
// Blocked: "N",
|
||||
// Cancelled: "N",
|
||||
// }
|
||||
|
||||
// if err != nil {
|
||||
// log.Printf("Error converting plan price: %s\n", err)
|
||||
// return fiber.ErrBadRequest
|
||||
// }
|
||||
// database.DB.Debug().Create(&user)
|
||||
// }
|
||||
|
||||
// transaction := models.Transaction{
|
||||
// Email: data.Data.Contact.Email,
|
||||
// PlanOrderID: data.Data.PlanOrderID,
|
||||
// Value: value,
|
||||
// PlanStartDate: data.Data.PlanStartDate,
|
||||
// PlanValidUntil: data.Data.PlanValidUntil,
|
||||
// PlanTitle: data.Data.PlanTitle,
|
||||
// Operation: "Compra",
|
||||
// Obs: "",
|
||||
// }
|
||||
// value, err := strconv.ParseFloat(data.Data.PlanPrice.Value, 32)
|
||||
|
||||
// database.DB.Debug().Create(&transaction)
|
||||
// if err != nil {
|
||||
// log.Printf("Error converting plan price: %s\n", err)
|
||||
// return fiber.ErrBadRequest
|
||||
// }
|
||||
|
||||
// return c.JSON(transaction)
|
||||
// }
|
||||
// transaction := models.Transaction{
|
||||
// Email: data.Data.Contact.Email,
|
||||
// PlanOrderID: data.Data.PlanOrderID,
|
||||
// Value: value,
|
||||
// PlanStartDate: data.Data.PlanStartDate,
|
||||
// PlanValidUntil: data.Data.PlanValidUntil,
|
||||
// PlanTitle: data.Data.PlanTitle,
|
||||
// Operation: "Compra",
|
||||
// Obs: "",
|
||||
// }
|
||||
|
||||
// database.DB.Debug().Create(&transaction)
|
||||
|
||||
// return c.JSON(transaction)
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -7,6 +7,7 @@ require (
|
|||
github.com/shirou/gopsutil/v3 v3.23.10
|
||||
github.com/spf13/viper v1.17.0
|
||||
golang.org/x/crypto v0.15.0
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gorm.io/driver/postgres v1.5.4
|
||||
gorm.io/gorm v1.25.5
|
||||
)
|
||||
|
|
@ -52,6 +53,7 @@ require (
|
|||
golang.org/x/sync v0.5.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -544,11 +544,15 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import (
|
|||
// Setup sets up the routes
|
||||
func Setup(app *fiber.App) {
|
||||
|
||||
// app.Post("/integration", controllers.WixIntegration)
|
||||
app.Post("/integration", controllers.WixIntegration)
|
||||
app.Post("/test", controllers.WixTest)
|
||||
|
||||
app.Get("/version", controllers.Version)
|
||||
|
||||
|
|
@ -18,6 +19,8 @@ func Setup(app *fiber.App) {
|
|||
app.Get("/users", controllers.GetUsers)
|
||||
app.Get("/groups", controllers.GetGroups)
|
||||
|
||||
app.Post("/user", controllers.CreateUser)
|
||||
|
||||
// Webhooks
|
||||
app.Post("/on_server_start", controllers.ServerStart)
|
||||
app.Post("/on_rtmp_connect", controllers.OnRtmpConnect)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"gopkg.in/gomail.v2"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
|
|
@ -19,3 +21,17 @@ func PrettyPrintJson(data interface{}) {
|
|||
}
|
||||
log.Println(string(b))
|
||||
}
|
||||
|
||||
func SendEmail(email string) {
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", "suporte@pcastlive.com")
|
||||
m.SetHeader("To", email)
|
||||
m.SetHeader("Subject", "Test Email from Go")
|
||||
m.SetBody("text/plain", "This is a test email sent from a Go application.")
|
||||
|
||||
d := gomail.NewDialer("smtp.kinghost.net", 465, "suporte@pcastlive.com", "@407Smc837")
|
||||
|
||||
if err := d.DialAndSend(m); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue