@@ -1,5 +1,6 @@
|
||||
import { createUserInsecure } from 'src/services/users/users.js'
|
||||
import { db } from 'src/lib/db'
|
||||
import { enforceAlphaNumeric } from 'src/services/helpers'
|
||||
|
||||
export const handler = async (req, _context) => {
|
||||
const body = JSON.parse(req.body)
|
||||
@@ -74,7 +75,7 @@ export const handler = async (req, _context) => {
|
||||
const newSeed = count === 1 ? `${seed}_${count}` : seed.slice(0,-1) + count
|
||||
return generateUniqueUserName(newSeed, count)
|
||||
}
|
||||
const userNameSeed = email.split('@')[0]
|
||||
const userNameSeed = enforceAlphaNumeric(email.split('@')[0])
|
||||
const userName = await generateUniqueUserName(userNameSeed) // TODO maybe come up with a better default userName?
|
||||
const input = {
|
||||
email,
|
||||
|
||||
@@ -11,3 +11,5 @@ export const foreignKeyReplacement = (input) => {
|
||||
})
|
||||
return output
|
||||
}
|
||||
|
||||
export const enforceAlphaNumeric = (string) => string.replace(/([^a-zA-Z\d_:])/g, '-')
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { db } from 'src/lib/db'
|
||||
import { foreignKeyReplacement } from 'src/services/helpers'
|
||||
import { foreignKeyReplacement, enforceAlphaNumeric } from 'src/services/helpers'
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
import { requireOwnership } from 'src/lib/owner'
|
||||
import { user } from 'src/services/users/users'
|
||||
|
||||
export const parts = () => {
|
||||
return db.part.findMany()
|
||||
@@ -40,7 +39,7 @@ export const updatePart = async ({ id, input }) => {
|
||||
requireAuth()
|
||||
await requireOwnership({partId: id})
|
||||
if(input.title) {
|
||||
input.title = input.title.replace(/([^a-zA-Z\d_:])/g, '-')
|
||||
input.title = enforceAlphaNumeric(input.title)
|
||||
}
|
||||
return db.part.update({
|
||||
data: foreignKeyReplacement(input),
|
||||
|
||||
@@ -2,6 +2,7 @@ import { db } from 'src/lib/db'
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
import { requireOwnership } from 'src/lib/owner'
|
||||
import { UserInputError } from '@redwoodjs/api'
|
||||
import { enforceAlphaNumeric } from 'src/services/helpers'
|
||||
|
||||
export const users = () => {
|
||||
requireAuth({ role: 'admin' })
|
||||
@@ -42,7 +43,7 @@ export const updateUserByUserName = async ({ userName, input }) => {
|
||||
requireAuth()
|
||||
await requireOwnership({userName})
|
||||
if(input.userName) {
|
||||
input.userName = input.userName.replace(/([^a-zA-Z\d_:])/g, '-')
|
||||
input.userName = enforceAlphaNumeric(input.userName)
|
||||
}
|
||||
if(input.userName && ['new', 'edit', 'update'].includes(input.userName)) { //TODO complete this and use a regexp so that it's not case sensitive, don't want someone with the userName eDiT
|
||||
throw new UserInputError(`You've tried to used a protected word as you userName, try something other than `)
|
||||
|
||||
Reference in New Issue
Block a user