Update referral.go to check for profanity in code (#2868)
## Description Checks if the code contains profanity ## Tests
This commit is contained in:
@@ -5,6 +5,7 @@ go 1.21
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
github.com/GoKillers/libsodium-go v0.0.0-20171022220152-dd733721c3cb
|
||||
github.com/TwiN/go-away v1.0.5
|
||||
github.com/avct/uasurfer v0.0.0-20191028135549-26b5daa857f1
|
||||
github.com/awa/go-iap v1.3.16
|
||||
github.com/aws/aws-sdk-go v1.34.13
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
enteTime "github.com/ente-io/museum/pkg/utils/time"
|
||||
"github.com/ente-io/stacktrace"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/TwiN/go-away"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -141,6 +142,12 @@ func (c *Controller) UpdateReferralCode(ctx *gin.Context, userID int64, code str
|
||||
if len(code) < 4 || len(code) > 20 {
|
||||
return stacktrace.Propagate(ente.NewBadRequestWithMessage("code length should be between 4 and 8"), "")
|
||||
}
|
||||
|
||||
// Check if the code contains any offensive language using the go-away library
|
||||
if goaway.IsProfane(code) {
|
||||
return stacktrace.Propagate(ente.NewBadRequestWithMessage("Referral code contains offensive language and cannot be used"), "")
|
||||
}
|
||||
|
||||
err := c.StorageBonus.AddNewCode(ctx, userID, code, isAdminEdit)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "failed to update referral code")
|
||||
|
||||
Reference in New Issue
Block a user