Kaynağa Gözat

fix: User name validation in backend and frontend error messages updates

Owen Diffey 3 yıl önce
ebeveyn
işleme
3d9a9567c8

+ 3 - 3
backend/logic/db/index.js

@@ -138,9 +138,9 @@ class _DBModule extends CoreClass {
 						return regex.emailSimple.test(email) && regex.ascii.test(email);
 					}, "Invalid email.");
 
-					// this.schemas.user
-					// 	.path("name")
-					// 	.validate(name => isLength(name, 1, 64) && regex.name.test(name), "Invalid name.");
+					this.schemas.user
+						.path("name")
+						.validate(name => isLength(name, 1, 64) && regex.name.test(name), "Invalid name.");
 
 					// Station
 					this.schemas.station

+ 3 - 3
frontend/src/pages/Settings/Tabs/Profile.vue

@@ -148,11 +148,11 @@ export default {
 
 			if (!validation.regex.name.test(name))
 				return new Toast(
-					"Invalid name format. Only letters, spaces, apostrophes and hyphens are allowed."
+					"Invalid name format. Only letters, numbers, spaces, apostrophes, underscores and hyphens are allowed."
 				);
-			if (name.replaceAll(/[ .'-]/g, "").length === 0)
+			if (name.replaceAll(/[0-9 .'_-]/g, "").length === 0)
 				return new Toast(
-					"Invalid name format. Only letters, spaces, apostrophes and hyphens are allowed, and there has to be at least one letter."
+					"Invalid name format. Only letters, numbers, spaces, apostrophes, underscores and hyphens are allowed, and there has to be at least one letter."
 				);
 
 			this.$refs.saveButton.status = "disabled";