fix: harden struts auth responses

This commit is contained in:
Codex
2026-04-01 10:33:02 +08:00
parent 589f33dc92
commit fb18c4d99a
6 changed files with 26 additions and 12 deletions

View File

@@ -31,16 +31,16 @@ public class ValidationAction extends ActionSupport {
@Override
public void validate() {
if (username == null || username.trim().length() < 3 || username.trim().length() > 20) {
addFieldError("username", "用户名长度需在 3 到 20 之间。 / Username must be between 3 and 20 characters.");
addFieldError("username", "用户名长度需在 3 到 20 个字符之间。/ Username must be between 3 and 20 characters.");
}
if (email == null || !email.contains("@") || email.indexOf('@') == email.length() - 1) {
addFieldError("email", "请输入有效邮箱。 / Enter a valid email address.");
addFieldError("email", "请输入有效邮箱。/ Enter a valid email address.");
}
if (age == null || age < 18 || age > 60) {
addFieldError("age", "年龄需在 18 到 60 之间。 / Age must be between 18 and 60.");
addFieldError("age", "年龄需在 18 到 60 之间。/ Age must be between 18 and 60.");
}
if (bio != null && bio.trim().length() > 240) {
addFieldError("bio", "简介不能超过 240 个字符。 / Bio must stay under 240 characters.");
addFieldError("bio", "简介不能超过 240 个字符。/ Bio must stay under 240 characters.");
}
}