Skip to content

Commit

Permalink
Update referral.go to check for profanity in code (#2868)
Browse files Browse the repository at this point in the history
## Description
Checks if the code contains profanity

## Tests
  • Loading branch information
brog-io authored Aug 26, 2024
1 parent 1df05a8 commit 93e2036
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions server/pkg/controller/storagebonus/referral.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 93e2036

Please sign in to comment.