force uppercase usernames
This commit is contained in:
parent
ccd4126953
commit
82d8e34560
6 changed files with 1595 additions and 5 deletions
|
|
@ -25,9 +25,9 @@ async function validateInputs(name: string, bio: string, username: string, avata
|
|||
}
|
||||
|
||||
if (username) {
|
||||
const alphanumericRegex = /^[a-zA-Z0-9]+$/;
|
||||
const alphanumericRegex = /^[a-z0-9_]+$/;
|
||||
if (!alphanumericRegex.test(username)) {
|
||||
throw error(400, 'Username must contain only letters and numbers');
|
||||
throw error(400, 'Username must contain only lowercase letters, numbers, and underscores');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ export async function POST({ request }) {
|
|||
const formData = await request.formData();
|
||||
const name = formData.get('name') as string;
|
||||
const bio = formData.get('bio') as string;
|
||||
const username = formData.get('username') as string;
|
||||
const username = (formData.get('username') as string)?.toLowerCase();
|
||||
const avatarFile = formData.get('avatar') as File | null;
|
||||
|
||||
await validateInputs(name, bio, username, avatarFile);
|
||||
|
|
|
|||
|
|
@ -5,11 +5,19 @@ import { eq } from 'drizzle-orm';
|
|||
import { isNameAppropriate } from '$lib/server/moderation';
|
||||
|
||||
export async function GET({ url }) {
|
||||
const username = url.searchParams.get('username');
|
||||
const username = url.searchParams.get('username')?.toLowerCase();
|
||||
if (!username) {
|
||||
return json({ available: false });
|
||||
}
|
||||
|
||||
const alphanumericRegex = /^[a-z0-9_]+$/;
|
||||
if (!alphanumericRegex.test(username)) {
|
||||
return json({
|
||||
available: false,
|
||||
reason: 'Username must contain only lowercase letters, numbers, and underscores'
|
||||
});
|
||||
}
|
||||
|
||||
if (!(await isNameAppropriate(username))) {
|
||||
return json({ available: false, reason: 'Inappropriate content' });
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue