From eba23c4f6e5bd08cddfafe478916514dd9a27acf Mon Sep 17 00:00:00 2001 From: Zeng1998 <1129142694@qq.com> Date: Tue, 29 Nov 2022 19:03:29 +0800 Subject: [PATCH] fix: add validation for user information update (#633) --- web/src/components/UpdateAccountDialog.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/src/components/UpdateAccountDialog.tsx b/web/src/components/UpdateAccountDialog.tsx index a7c29132..a9cdac5b 100644 --- a/web/src/components/UpdateAccountDialog.tsx +++ b/web/src/components/UpdateAccountDialog.tsx @@ -6,6 +6,14 @@ import { userService } from "../services"; import Icon from "./Icon"; import { generateDialog } from "./Dialog"; import toastHelper from "./Toast"; +import { validate, ValidatorConfig } from "../helpers/validator"; + +const validateConfig: ValidatorConfig = { + minLength: 4, + maxLength: 320, + noSpace: true, + noChinese: true, +}; type Props = DialogProps; @@ -63,6 +71,12 @@ const UpdateAccountDialog: React.FC = ({ destroy }: Props) => { return; } + const usernameValidResult = validate(state.username, validateConfig); + if (!usernameValidResult.result) { + toastHelper.error(t("common.username") + ": " + usernameValidResult.reason); + return; + } + try { const user = userService.getState().user as User; const userPatch: UserPatch = {