mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: add validation for display name length in user creation and update requests
This commit is contained in:
@@ -12,12 +12,12 @@
|
|||||||
let error = '';
|
let error = '';
|
||||||
let title = '';
|
let title = '';
|
||||||
let content = '';
|
let content = '';
|
||||||
let selectedSyntax = data.options.syntaxes[0];
|
let selectedSyntax = data.options?.syntaxes[0];
|
||||||
let expiresIn: number = 0;
|
let expiresIn: number = 0;
|
||||||
let selectedVisibility = data.options.visibilities[0].value;
|
let selectedVisibility = data.options?.visibilities[0].value;
|
||||||
let password = '';
|
let password = '';
|
||||||
|
|
||||||
const syntaxOptions = data.options.syntaxes.map((lang: string) => ({
|
const syntaxOptions = data.options?.syntaxes.map((lang: string) => ({
|
||||||
value: lang,
|
value: lang,
|
||||||
label: displayNames[lang] ?? lang.charAt(0).toUpperCase() + lang.slice(1)
|
label: displayNames[lang] ?? lang.charAt(0).toUpperCase() + lang.slice(1)
|
||||||
}));
|
}));
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
{ value: 315360000000, label: 'Expire in 10 Years' }
|
{ value: 315360000000, label: 'Expire in 10 Years' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const visibilityOptions = data.options.visibilities.map(
|
const visibilityOptions = data.options?.visibilities.map(
|
||||||
(visibility: { value: number; displayName: string }) => ({
|
(visibility: { value: number; displayName: string }) => ({
|
||||||
value: visibility.value,
|
value: visibility.value,
|
||||||
label: visibility.displayName
|
label: visibility.displayName
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
|
||||||
body,
|
body,
|
||||||
h1,
|
h1,
|
||||||
h2,
|
h2,
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||||
|
const allowedHosts = process.env.VITE_ALLOWED_HOSTS
|
||||||
|
? process.env.VITE_ALLOWED_HOSTS.split(',')
|
||||||
|
: ['localhost'];
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [tailwindcss(), sveltekit()],
|
plugins: [tailwindcss(), sveltekit()],
|
||||||
@@ -10,5 +13,8 @@ export default defineConfig({
|
|||||||
proxy: {
|
proxy: {
|
||||||
'/api': apiUrl
|
'/api': apiUrl
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
preview: {
|
||||||
|
allowedHosts: allowedHosts
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
}
|
}
|
||||||
if (!IsValidPassword(request.Password))
|
if (!IsValidPassword(request.Password))
|
||||||
return BadRequest(new { message = "Password should have at least 8 characters, including uppercase, lowercase, and digits." });
|
return BadRequest(new { message = "Password should have at least 8 characters, including uppercase, lowercase, and digits." });
|
||||||
|
if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26)
|
||||||
|
return BadRequest(new { message = "Display name should not exceed 26 characters." });
|
||||||
|
|
||||||
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
||||||
return Ok(new
|
return Ok(new
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace SharpbinV3.Server.DTOs
|
|||||||
if (DisplayName != null) {
|
if (DisplayName != null) {
|
||||||
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
if (DisplayName.Length < 3 || DisplayName.Length > 26)
|
||||||
{
|
{
|
||||||
results.Add(new ValidationResult("DisplayName must be between 3 and 50 characters.", [nameof(DisplayName)]));
|
results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Email != null)
|
if (Email != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user