Skip to content

Commit

Permalink
refactor: Include sanity check for name color
Browse files Browse the repository at this point in the history
  • Loading branch information
matthe815 committed Aug 1, 2024
1 parent 07235e1 commit b0ff26f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/pages/api/account/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isBlank, isBoolean } from '@/lib/utils/utils'
import { isValidCoverRegion } from '@/lib/constants/forms/coverRegions'
import { isValidCoverType } from '@/lib/constants/forms/coverTypes'
import { isValidOverlay } from '@/lib/constants/forms/overlays'
import { BACKGROUNDS } from '@/lib/constants/forms/backgrounds'
import { isValidFlag } from '@/lib/constants/forms/flags'
import { isValidCoin } from '@/lib/constants/forms/coins'
import { isValidFont } from '@/lib/constants/forms/fonts'
Expand All @@ -29,26 +28,26 @@ async function updateTagSettings (request, response) {
} = request.body
const username = request.session?.username

function validateFriendCode () {
if (!request.body.comment) {
return true
}

return true
}

if (!validateFriendCode()) {
return response
.status(HTTP_CODE.BAD_REQUEST)
.send({ error: 'Invalid data' })
}

if (!username) {
return response
.status(HTTP_CODE.UNAUTHORIZED)
.json({ error: 'Unauthorized' })
}

if (nameColor) {
if (nameColor.length !== 7) {
return response
.status(HTTP_CODE.BAD_REQUEST)
.send({ error: 'Invalid data' })
}

if (!(/(#[a-fA-F0-9]{6})/.test(nameColor))) {
return response
.status(HTTP_CODE.BAD_REQUEST)
.send({ error: 'Invalid data' })
}
}

if (
isBlank(nameOnRiiTag) ||
isBlank(coverRegion) ||
Expand Down

0 comments on commit b0ff26f

Please sign in to comment.