From 5f702ca418b3d099b5d2a39f1434db17361ecd46 Mon Sep 17 00:00:00 2001 From: DacongDA Date: Fri, 25 Jul 2025 00:39:01 +0800 Subject: [PATCH] feat: make enableErrorMask work for corner cases by moving checks from controller to Translate() (#3996) --- controllers/util.go | 7 ------- i18n/locales/ar/data.json | 2 +- i18n/locales/cs/data.json | 2 +- i18n/locales/de/data.json | 2 +- i18n/locales/en/data.json | 2 +- i18n/locales/es/data.json | 2 +- i18n/locales/fa/data.json | 2 +- i18n/locales/fi/data.json | 2 +- i18n/locales/fr/data.json | 2 +- i18n/locales/he/data.json | 2 +- i18n/locales/id/data.json | 2 +- i18n/locales/it/data.json | 2 +- i18n/locales/ja/data.json | 2 +- i18n/locales/kk/data.json | 2 +- i18n/locales/ko/data.json | 2 +- i18n/locales/ms/data.json | 2 +- i18n/locales/nl/data.json | 2 +- i18n/locales/pl/data.json | 2 +- i18n/locales/pt/data.json | 2 +- i18n/locales/ru/data.json | 2 +- i18n/locales/sk/data.json | 2 +- i18n/locales/sv/data.json | 2 +- i18n/locales/tr/data.json | 2 +- i18n/locales/uk/data.json | 2 +- i18n/locales/vi/data.json | 2 +- i18n/locales/zh/data.json | 2 +- i18n/util.go | 20 ++++++++++++++++++++ object/check_util.go | 3 ++- 28 files changed, 47 insertions(+), 33 deletions(-) diff --git a/controllers/util.go b/controllers/util.go index d5751562..d5bef5dc 100644 --- a/controllers/util.go +++ b/controllers/util.go @@ -54,13 +54,6 @@ func (c *ApiController) ResponseError(error string, data ...interface{}) { return } - enableErrorMask := conf.GetConfigBool("enableErrorMask") - if enableErrorMask { - if strings.HasPrefix(error, "The user: ") && strings.HasSuffix(error, " doesn't exist") || strings.HasPrefix(error, "用户: ") && strings.HasSuffix(error, "不存在") { - error = c.T("check:password or code is incorrect") - } - } - resp := &Response{Status: "error", Msg: error} c.ResponseJsonData(resp, data...) } diff --git a/i18n/locales/ar/data.json b/i18n/locales/ar/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/ar/data.json +++ b/i18n/locales/ar/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/cs/data.json b/i18n/locales/cs/data.json index d341c454..89c48fb2 100644 --- a/i18n/locales/cs/data.json +++ b/i18n/locales/cs/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Vaše oblast neumožňuje registraci pomocí telefonu", "password or code is incorrect": "heslo nebo kód je nesprávné", - "password or code is incorrect, you have %d remaining chances": "heslo nebo kód je nesprávné, máte %d zbývajících pokusů", + "password or code is incorrect, you have %s remaining chances": "heslo nebo kód je nesprávné, máte %s zbývajících pokusů", "unsupported password type: %s": "nepodporovaný typ hesla: %s" }, "enforcer": { diff --git a/i18n/locales/de/data.json b/i18n/locales/de/data.json index 34f44af9..2cd83a52 100644 --- a/i18n/locales/de/data.json +++ b/i18n/locales/de/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Ihre Region ist nicht berechtigt, sich telefonisch anzumelden", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "Das Passwort oder der Code ist falsch. Du hast noch %d Versuche übrig", + "password or code is incorrect, you have %s remaining chances": "Das Passwort oder der Code ist falsch. Du hast noch %s Versuche übrig", "unsupported password type: %s": "Nicht unterstützter Passworttyp: %s" }, "enforcer": { diff --git a/i18n/locales/en/data.json b/i18n/locales/en/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/en/data.json +++ b/i18n/locales/en/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/es/data.json b/i18n/locales/es/data.json index 20664aa9..23bc23dd 100644 --- a/i18n/locales/es/data.json +++ b/i18n/locales/es/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Tu región no está permitida para registrarse por teléfono", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "Contraseña o código incorrecto, tienes %d intentos restantes", + "password or code is incorrect, you have %s remaining chances": "Contraseña o código incorrecto, tienes %s intentos restantes", "unsupported password type: %s": "Tipo de contraseña no compatible: %s" }, "enforcer": { diff --git a/i18n/locales/fa/data.json b/i18n/locales/fa/data.json index a21d58f6..949409da 100644 --- a/i18n/locales/fa/data.json +++ b/i18n/locales/fa/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "منطقه شما اجازه ثبت‌نام با تلفن را ندارد", "password or code is incorrect": "رمز عبور یا کد نادرست است", - "password or code is incorrect, you have %d remaining chances": "رمز عبور یا کد نادرست است، شما %d فرصت باقی‌مانده دارید", + "password or code is incorrect, you have %s remaining chances": "رمز عبور یا کد نادرست است، شما %s فرصت باقی‌مانده دارید", "unsupported password type: %s": "نوع رمز عبور پشتیبانی نشده: %s" }, "enforcer": { diff --git a/i18n/locales/fi/data.json b/i18n/locales/fi/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/fi/data.json +++ b/i18n/locales/fi/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/fr/data.json b/i18n/locales/fr/data.json index 1db8655e..7cb214b4 100644 --- a/i18n/locales/fr/data.json +++ b/i18n/locales/fr/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Votre région n'est pas autorisée à s'inscrire par téléphone", "password or code is incorrect": "mot de passe ou code invalide", - "password or code is incorrect, you have %d remaining chances": "Le mot de passe ou le code est incorrect, il vous reste %d chances", + "password or code is incorrect, you have %s remaining chances": "Le mot de passe ou le code est incorrect, il vous reste %s chances", "unsupported password type: %s": "Type de mot de passe non pris en charge : %s" }, "enforcer": { diff --git a/i18n/locales/he/data.json b/i18n/locales/he/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/he/data.json +++ b/i18n/locales/he/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/id/data.json b/i18n/locales/id/data.json index 531b378f..b7574346 100644 --- a/i18n/locales/id/data.json +++ b/i18n/locales/id/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Wilayah Anda tidak diizinkan untuk mendaftar melalui telepon", "password or code is incorrect": "kata sandi atau kode salah", - "password or code is incorrect, you have %d remaining chances": "Sandi atau kode salah, Anda memiliki %d kesempatan tersisa", + "password or code is incorrect, you have %s remaining chances": "Sandi atau kode salah, Anda memiliki %s kesempatan tersisa", "unsupported password type: %s": "jenis sandi tidak didukung: %s" }, "enforcer": { diff --git a/i18n/locales/it/data.json b/i18n/locales/it/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/it/data.json +++ b/i18n/locales/it/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/ja/data.json b/i18n/locales/ja/data.json index fd1c2681..fa315944 100644 --- a/i18n/locales/ja/data.json +++ b/i18n/locales/ja/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "あなたの地域は電話でサインアップすることができません", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "パスワードまたはコードが間違っています。あと%d回の試行機会があります", + "password or code is incorrect, you have %s remaining chances": "パスワードまたはコードが間違っています。あと%s回の試行機会があります", "unsupported password type: %s": "サポートされていないパスワードタイプ:%s" }, "enforcer": { diff --git a/i18n/locales/kk/data.json b/i18n/locales/kk/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/kk/data.json +++ b/i18n/locales/kk/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/ko/data.json b/i18n/locales/ko/data.json index 3b1146bc..36bfeb0b 100644 --- a/i18n/locales/ko/data.json +++ b/i18n/locales/ko/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "당신의 지역은 전화로 가입할 수 없습니다", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "암호 또는 코드가 올바르지 않습니다. %d번의 기회가 남아 있습니다", + "password or code is incorrect, you have %s remaining chances": "암호 또는 코드가 올바르지 않습니다. %s번의 기회가 남아 있습니다", "unsupported password type: %s": "지원되지 않는 암호 유형: %s" }, "enforcer": { diff --git a/i18n/locales/ms/data.json b/i18n/locales/ms/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/ms/data.json +++ b/i18n/locales/ms/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/nl/data.json b/i18n/locales/nl/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/nl/data.json +++ b/i18n/locales/nl/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/pl/data.json b/i18n/locales/pl/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/pl/data.json +++ b/i18n/locales/pl/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/pt/data.json b/i18n/locales/pt/data.json index 31fd6442..d8341473 100644 --- a/i18n/locales/pt/data.json +++ b/i18n/locales/pt/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "senha ou código incorreto", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/ru/data.json b/i18n/locales/ru/data.json index 740a9a28..0c2c2364 100644 --- a/i18n/locales/ru/data.json +++ b/i18n/locales/ru/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Ваш регион не разрешает регистрацию по телефону", "password or code is incorrect": "неправильный пароль или код", - "password or code is incorrect, you have %d remaining chances": "Неправильный пароль или код, у вас осталось %d попыток", + "password or code is incorrect, you have %s remaining chances": "Неправильный пароль или код, у вас осталось %s попыток", "unsupported password type: %s": "неподдерживаемый тип пароля: %s" }, "enforcer": { diff --git a/i18n/locales/sk/data.json b/i18n/locales/sk/data.json index 0a9851a4..3f0a1110 100644 --- a/i18n/locales/sk/data.json +++ b/i18n/locales/sk/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Váš región neumožňuje registráciu cez telefón", "password or code is incorrect": "heslo alebo kód je nesprávne", - "password or code is incorrect, you have %d remaining chances": "heslo alebo kód je nesprávne, máte %d zostávajúcich pokusov", + "password or code is incorrect, you have %s remaining chances": "heslo alebo kód je nesprávne, máte %s zostávajúcich pokusov", "unsupported password type: %s": "nepodporovaný typ hesla: %s" }, "enforcer": { diff --git a/i18n/locales/sv/data.json b/i18n/locales/sv/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/sv/data.json +++ b/i18n/locales/sv/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/tr/data.json b/i18n/locales/tr/data.json index bbfda58d..b004414b 100644 --- a/i18n/locales/tr/data.json +++ b/i18n/locales/tr/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "şifre veya kod hatalı", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/uk/data.json b/i18n/locales/uk/data.json index 0c46e3b3..0c9ade04 100644 --- a/i18n/locales/uk/data.json +++ b/i18n/locales/uk/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Your region is not allow to signup by phone", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "password or code is incorrect, you have %d remaining chances", + "password or code is incorrect, you have %s remaining chances": "password or code is incorrect, you have %s remaining chances", "unsupported password type: %s": "unsupported password type: %s" }, "enforcer": { diff --git a/i18n/locales/vi/data.json b/i18n/locales/vi/data.json index 70dfa3e3..648792d2 100644 --- a/i18n/locales/vi/data.json +++ b/i18n/locales/vi/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"", "Your region is not allow to signup by phone": "Vùng của bạn không được phép đăng ký bằng điện thoại", "password or code is incorrect": "password or code is incorrect", - "password or code is incorrect, you have %d remaining chances": "Mật khẩu hoặc mã không chính xác, bạn còn %d lần cơ hội", + "password or code is incorrect, you have %s remaining chances": "Mật khẩu hoặc mã không chính xác, bạn còn %s lần cơ hội", "unsupported password type: %s": "Loại mật khẩu không được hỗ trợ: %s" }, "enforcer": { diff --git a/i18n/locales/zh/data.json b/i18n/locales/zh/data.json index 00f4cc49..f056cece 100644 --- a/i18n/locales/zh/data.json +++ b/i18n/locales/zh/data.json @@ -85,7 +85,7 @@ "Your password has expired. Please reset your password by clicking \\\"Forgot password\\\"": "您的密码已过期。请点击 \\\"忘记密码\\\" 以重置密码", "Your region is not allow to signup by phone": "所在地区不支持手机号注册", "password or code is incorrect": "密码错误", - "password or code is incorrect, you have %d remaining chances": "密码错误,您还有 %d 次尝试的机会", + "password or code is incorrect, you have %s remaining chances": "密码错误,您还有 %s 次尝试的机会", "unsupported password type: %s": "不支持的密码类型: %s" }, "enforcer": { diff --git a/i18n/util.go b/i18n/util.go index 8b2d6b56..ad55b8ac 100644 --- a/i18n/util.go +++ b/i18n/util.go @@ -19,14 +19,21 @@ import ( "fmt" "strings" + "github.com/casdoor/casdoor/conf" "github.com/casdoor/casdoor/util" ) +var enableErrorMask = false + //go:embed locales/*/data.json var f embed.FS var langMap = make(map[string]map[string]map[string]string) // for example : langMap[en][account][Invalid information] = Invalid information +func init() { + enableErrorMask = conf.GetConfigBool("enableErrorMask") +} + func getI18nFilePath(category string, language string) string { if category == "backend" { return fmt.Sprintf("../i18n/locales/%s/data.json", language) @@ -74,6 +81,15 @@ func applyData(data1 *I18nData, data2 *I18nData) { } func Translate(language string, errorText string) string { + modified := false + if enableErrorMask { + if errorText == "general:The user: %s doesn't exist" || + errorText == "check:password or code is incorrect, you have %s remaining chances" { + modified = true + errorText = "check:password or code is incorrect" + } + } + tokens := strings.SplitN(errorText, ":", 2) if !strings.Contains(errorText, ":") || len(tokens) != 2 { return fmt.Sprintf("Translate error: the error text doesn't contain \":\", errorText = %s", errorText) @@ -97,5 +113,9 @@ func Translate(language string, errorText string) string { if res == "" { res = tokens[1] } + + if modified { + res += "%.s" + } return res } diff --git a/object/check_util.go b/object/check_util.go index 9e62752a..74f93f15 100644 --- a/object/check_util.go +++ b/object/check_util.go @@ -17,6 +17,7 @@ package object import ( "fmt" "regexp" + "strconv" "time" "github.com/casdoor/casdoor/i18n" @@ -100,7 +101,7 @@ func recordSigninErrorInfo(user *User, lang string, options ...bool) error { if leftChances == 0 && enableCaptcha { return fmt.Errorf(i18n.Translate(lang, "check:password or code is incorrect")) } else if leftChances >= 0 { - return fmt.Errorf(i18n.Translate(lang, "check:password or code is incorrect, you have %d remaining chances"), leftChances) + return fmt.Errorf(i18n.Translate(lang, "check:password or code is incorrect, you have %s remaining chances"), strconv.Itoa(leftChances)) } // don't show the chance error message if the user has no chance left