mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-02-02 17:24:50 -05:00
🔧 fix(handlers_web.go): remove unused import and variable 'strconv'
✨ feat(handlers_web.go): add support for handling form data in 'handleRequestServicePostForm' function 🔧 fix(handlers_web.go): fix parsing and setting of form data in 'handleRequestServicePostForm' function
This commit is contained in:
parent
910a779f66
commit
56ce1519b2
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@ -135,6 +134,8 @@ func (s *Server) handleRequestServiceForm(c *fiber.Ctx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reverse := true
|
||||||
return c.Render("request_service", fiber.Map{
|
return c.Render("request_service", fiber.Map{
|
||||||
"Title": "Request a service",
|
"Title": "Request a service",
|
||||||
"Current": "request",
|
"Current": "request",
|
||||||
@ -143,10 +144,30 @@ func (s *Server) handleRequestServiceForm(c *fiber.Ctx) error {
|
|||||||
"Difficulty": difficulty,
|
"Difficulty": difficulty,
|
||||||
"Id": id,
|
"Id": id,
|
||||||
},
|
},
|
||||||
|
"Attributes": database.ServiceAttributes.GetSortedAttributes(reverse),
|
||||||
"Error": c.Query("error", ""),
|
"Error": c.Query("error", ""),
|
||||||
}, "base")
|
}, "base")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestFormData struct {
|
||||||
|
Type string `form:"type"`
|
||||||
|
Category string `form:"category"`
|
||||||
|
Name string `form:"name"`
|
||||||
|
Description string `form:"description"`
|
||||||
|
Urls string `form:"urls"`
|
||||||
|
LogoUrl string `form:"logo_url"`
|
||||||
|
TosUrls string `form:"tos_urls"`
|
||||||
|
OnionUrls string `form:"onion_urls"`
|
||||||
|
Tags string `form:"tags"`
|
||||||
|
Xmr bool `form:"xmr"`
|
||||||
|
Btc bool `form:"btc"`
|
||||||
|
Ln bool `form:"ln"`
|
||||||
|
Fiat bool `form:"fiat"`
|
||||||
|
Cash bool `form:"cash"`
|
||||||
|
KYCLevel int `form:"kyc_level"`
|
||||||
|
Attributes []string `form:"attributes"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleRequestServicePostForm(c *fiber.Ctx) error {
|
func (s *Server) handleRequestServicePostForm(c *fiber.Ctx) error {
|
||||||
nonce, id := c.FormValue("pow-nonce"), c.FormValue("pow-id")
|
nonce, id := c.FormValue("pow-nonce"), c.FormValue("pow-id")
|
||||||
log.Printf("Nonce: %v, ID: %v", nonce, id)
|
log.Printf("Nonce: %v, ID: %v", nonce, id)
|
||||||
@ -154,29 +175,19 @@ func (s *Server) handleRequestServicePostForm(c *fiber.Ctx) error {
|
|||||||
return c.Redirect("/request/service?error=invalid-captcha")
|
return c.Redirect("/request/service?error=invalid-captcha")
|
||||||
}
|
}
|
||||||
|
|
||||||
// KYC Level
|
data := new(RequestFormData)
|
||||||
log.Printf("KYC Level: %v", c.FormValue("kyc_level"))
|
if err := c.BodyParser(data); err != nil {
|
||||||
klInt, err := strconv.Atoi(c.FormValue("kyc_level"))
|
log.Error().Err(err).Msg("Could not parse form data")
|
||||||
log.Printf("KYC Level Int: %v", klInt)
|
return c.Redirect("/request/service?error=invalid-form")
|
||||||
if err != nil || klInt < 0 || klInt >= 4 {
|
}
|
||||||
log.Error().Err(err).Msgf("Invalid KYC Level value: %v", c.FormValue("kyc_level"))
|
|
||||||
|
if data.KYCLevel < 0 || data.KYCLevel >= 4 {
|
||||||
|
log.Error().Msgf("Invalid KYC Level value: %v", c.FormValue("kyc_level"))
|
||||||
return c.Redirect("/request/service?error=invalid-kyc-level")
|
return c.Redirect("/request/service?error=invalid-kyc-level")
|
||||||
}
|
}
|
||||||
|
|
||||||
var serviceType service.Type
|
|
||||||
switch c.FormValue("type") {
|
|
||||||
case "exchange":
|
|
||||||
serviceType = service.TypeExchange
|
|
||||||
case "service":
|
|
||||||
serviceType = service.TypeService
|
|
||||||
case "wallet":
|
|
||||||
serviceType = service.TypeWallet
|
|
||||||
default:
|
|
||||||
return c.Redirect("/request/service?error=invalid-service-type")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse tags
|
// Parse tags
|
||||||
tags := strings.ReplaceAll(c.FormValue("tags"), " ", ",")
|
tags := strings.ReplaceAll(data.Tags, " ", ",")
|
||||||
// Remove trailing commas
|
// Remove trailing commas
|
||||||
tags = strings.TrimSuffix(tags, ",")
|
tags = strings.TrimSuffix(tags, ",")
|
||||||
// Remove duplicate commas
|
// Remove duplicate commas
|
||||||
@ -186,22 +197,27 @@ func (s *Server) handleRequestServicePostForm(c *fiber.Ctx) error {
|
|||||||
// Convert to lowercase
|
// Convert to lowercase
|
||||||
tags = strings.ToLower(tags)
|
tags = strings.ToLower(tags)
|
||||||
|
|
||||||
_, err = database.Client.Service.Create().
|
log.Printf("%+v", data)
|
||||||
SetName(strings.ToLower(c.FormValue("name"))).
|
|
||||||
SetDescription(c.FormValue("description")).
|
_, err := database.Client.Service.Create().
|
||||||
SetType(serviceType).
|
SetName(strings.ToLower(data.Name)).
|
||||||
SetLogoURL(utils.UrlParser(c.FormValue("logo_url"))).
|
SetDescription(data.Description).
|
||||||
SetUrls(utils.UrlListParser(c.FormValue("urls"))).
|
SetType(service.Type(data.Type)).
|
||||||
SetTosUrls(utils.UrlListParser(c.FormValue("tos_urls"))).
|
SetLogoURL(utils.UrlParser(data.LogoUrl)).
|
||||||
SetOnionUrls(utils.UrlListParser(c.FormValue("tor_urls"))).
|
SetUrls(utils.UrlListParser(data.Urls)).
|
||||||
|
SetTosUrls(utils.UrlListParser(data.TosUrls)).
|
||||||
|
SetOnionUrls(utils.UrlListParser(data.OnionUrls)).
|
||||||
SetTags(tags).
|
SetTags(tags).
|
||||||
SetXmr(c.FormValue("xmr") == "on").
|
SetXmr(data.Xmr).
|
||||||
SetBtc(c.FormValue("btc") == "on").
|
SetBtc(data.Btc).
|
||||||
SetLightning(c.FormValue("ln") == "on").
|
SetLightning(data.Ln).
|
||||||
SetFiat(c.FormValue("fiat") == "on").
|
SetFiat(data.Fiat).
|
||||||
SetCash(c.FormValue("cash") == "on").
|
SetCash(data.Cash).
|
||||||
SetKycLevel(klInt).
|
SetKycLevel(data.KYCLevel).
|
||||||
SetPending(true).
|
SetCategory(data.Category).
|
||||||
|
SetAttributes(strings.Join(data.Attributes, ",")).
|
||||||
|
SetPending(false).
|
||||||
|
SetListed(true).
|
||||||
Save(c.Context())
|
Save(c.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Could not save service to database")
|
log.Error().Err(err).Msg("Could not save service to database")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user