Require a captcha on the backend
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"github.com/ProjectSegfault/publapi/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ProjectSegfault/publapi/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/kataras/hcaptcha"
|
||||
)
|
||||
|
||||
type Userstruct struct {
|
||||
@@ -35,6 +38,14 @@ type Userinfo struct {
|
||||
Loc string `json:"loc"`
|
||||
}
|
||||
|
||||
// Hcaptcha setup
|
||||
|
||||
var (
|
||||
secretKey string = os.Getenv("PUBLAPI_HCAPTCHA_SECRET")
|
||||
siteKey string = os.Getenv("PUBLAPI_HCAPTCHA_SITE")
|
||||
client = hcaptcha.New(secretKey)
|
||||
)
|
||||
|
||||
func userdata(username, usersonline, ops string) Userinfo {
|
||||
regex := "(^| )" + username + "($| )"
|
||||
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
||||
@@ -144,7 +155,14 @@ func UsersPage(c *fiber.Ctx) error {
|
||||
var userinfostruct []Userinfo
|
||||
for i := 0; i < len(usersarr); i++ {
|
||||
uname := string(usersarr[i])
|
||||
userinfostruct = append(userinfostruct, userdata(uname, strings.TrimSuffix(usersonlinededup, "\n"), strings.TrimSuffix(opstr, "\n")))
|
||||
userinfostruct = append(
|
||||
userinfostruct,
|
||||
userdata(
|
||||
uname,
|
||||
strings.TrimSuffix(usersonlinededup, "\n"),
|
||||
strings.TrimSuffix(opstr, "\n"),
|
||||
),
|
||||
)
|
||||
}
|
||||
data := Userstruct{
|
||||
Status: c.Response().StatusCode(),
|
||||
|
Reference in New Issue
Block a user