feat: refactor backend i18n (#1373)

* fix: handle the dataSourceName when DB changes

* reduce duplication of code

* feat: refactor translation error message

* feat: use json intsead of ini file

* remove useless translation

* fix translate problems

* remove useless addition

* fix pr problems

* fix pr problems

* fix split problem

* use gofumpt to fmt code

* use crowdin to execute backend translation

* fix pr problems

* refactor: change translation file structure same as frontend

* delete useless output

* update go.mod
This commit is contained in:
Mr Forest
2022-12-07 13:13:23 +08:00
committed by GitHub
parent 96566a626b
commit 1bb3d2dea9
49 changed files with 1604 additions and 1301 deletions

View File

@ -102,7 +102,7 @@ type Captcha struct {
// @router /signup [post]
func (c *ApiController) Signup() {
if c.GetSessionUsername() != "" {
c.ResponseError(c.T("SignUpErr.SignOutFirst"), c.GetSessionUsername())
c.ResponseError(c.T("account:Please sign out first before signing up"), c.GetSessionUsername())
return
}
@ -115,7 +115,7 @@ func (c *ApiController) Signup() {
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
if !application.EnableSignUp {
c.ResponseError(c.T("SignUpErr.DoNotAllowSignUp"))
c.ResponseError(c.T("account:The application does not allow to sign up new account"))
return
}
@ -129,7 +129,7 @@ func (c *ApiController) Signup() {
if application.IsSignupItemVisible("Email") && application.GetSignupItemRule("Email") != "No verification" && form.Email != "" {
checkResult := object.CheckVerificationCode(form.Email, form.EmailCode, c.GetAcceptLanguage())
if len(checkResult) != 0 {
c.ResponseError(c.T("EmailErr.EmailCheckResult"), checkResult)
c.ResponseError(c.T("account:Email: %s"), checkResult)
return
}
}
@ -139,7 +139,7 @@ func (c *ApiController) Signup() {
checkPhone = fmt.Sprintf("+%s%s", form.PhonePrefix, form.Phone)
checkResult := object.CheckVerificationCode(checkPhone, form.PhoneCode, c.GetAcceptLanguage())
if len(checkResult) != 0 {
c.ResponseError(c.T("PhoneErr.PhoneCheckResult"), checkResult)
c.ResponseError(c.T("account:Phone: %s"), checkResult)
return
}
}
@ -163,7 +163,7 @@ func (c *ApiController) Signup() {
initScore, err := getInitScore()
if err != nil {
c.ResponseError(fmt.Errorf(c.T("InitErr.InitScoreFailed"), err).Error())
c.ResponseError(fmt.Errorf(c.T("account:Get init score failed, error: %w"), err).Error())
return
}
@ -209,7 +209,7 @@ func (c *ApiController) Signup() {
affected := object.AddUser(user)
if !affected {
c.ResponseError(c.T("UserErr.InvalidInformation"), util.StructToJson(user))
c.ResponseError(c.T("account:Invalid information"), util.StructToJson(user))
return
}

View File

@ -86,7 +86,7 @@ func (c *ApiController) GetUserApplication() {
id := c.Input().Get("id")
user := object.GetUser(id)
if user == nil {
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), id))
c.ResponseError(fmt.Sprintf(c.T("application:The user: %s doesn't exist"), id))
return
}
@ -113,7 +113,7 @@ func (c *ApiController) GetOrganizationApplications() {
sortOrder := c.Input().Get("sortOrder")
if organization == "" {
c.ResponseError(c.T("ParameterErr.OrgMissingErr"))
c.ResponseError(c.T("application:Parameter organization is missing"))
return
}

View File

@ -65,7 +65,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
return
}
if !allowed {
c.ResponseError(c.T("AuthErr.Unauthorized"))
c.ResponseError(c.T("auth:Unauthorized operation"))
return
}
@ -84,7 +84,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
codeChallenge := c.Input().Get("code_challenge")
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
c.ResponseError(c.T("AuthErr.ChallengeMethodErr"))
c.ResponseError(c.T("auth:Challenge method should be S256"))
return
}
code := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, c.Ctx.Request.Host, c.GetAcceptLanguage())
@ -205,7 +205,7 @@ func (c *ApiController) Login() {
if form.Username != "" {
if form.Type == ResponseTypeLogin {
if c.GetSessionUsername() != "" {
c.ResponseError(c.T("LoginErr.SignOutFirst"), c.GetSessionUsername())
c.ResponseError(c.T("auth:Please sign out first before signing in"), c.GetSessionUsername())
return
}
}
@ -231,7 +231,7 @@ func (c *ApiController) Login() {
} else {
verificationCodeType = "phone"
if len(form.PhonePrefix) == 0 {
responseText := fmt.Sprintf(c.T("PhoneErr.NoPrefix"), verificationCodeType)
responseText := fmt.Sprintf(c.T("auth:%s No phone prefix"), verificationCodeType)
c.ResponseError(responseText)
return
}
@ -256,13 +256,13 @@ func (c *ApiController) Login() {
user = object.GetUserByFields(form.Organization, form.Username)
if user == nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.UserDoNotExist"), form.Organization, form.Username))
c.ResponseError(fmt.Sprintf(c.T("auth:The user: %s/%s doesn't exist"), form.Organization, form.Username))
return
}
} else {
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
if application == nil {
c.ResponseError(fmt.Sprintf("The application: %s does not exist", form.Application))
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), form.Application))
return
}
@ -274,7 +274,7 @@ func (c *ApiController) Login() {
}
if !isHuman {
c.ResponseError("Turing test failed.")
c.ResponseError(c.T("auth:Turing test failed."))
return
}
}
@ -288,7 +288,7 @@ func (c *ApiController) Login() {
} else {
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), form.Application))
return
}
@ -302,7 +302,7 @@ func (c *ApiController) Login() {
} else if form.Provider != "" {
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), form.Application))
return
}
@ -310,7 +310,7 @@ func (c *ApiController) Login() {
provider := object.GetProvider(util.GetId("admin", form.Provider))
providerItem := application.GetProviderItem(provider.Name)
if !providerItem.IsProviderVisible() {
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotEnabled"), provider.Name))
c.ResponseError(fmt.Sprintf(c.T("auth:The provider: %s is not enabled for the application"), provider.Name))
return
}
@ -334,14 +334,14 @@ func (c *ApiController) Login() {
idProvider := idp.GetIdProvider(provider.Type, provider.SubType, clientId, clientSecret, provider.AppId, form.RedirectUri, provider.Domain, provider.CustomAuthUrl, provider.CustomTokenUrl, provider.CustomUserInfoUrl)
if idProvider == nil {
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotSupported"), provider.Type))
c.ResponseError(fmt.Sprintf(c.T("auth:The provider type: %s is not supported"), provider.Type))
return
}
setHttpClient(idProvider, provider.Type)
if form.State != conf.GetConfigString("authState") && form.State != application.Name {
c.ResponseError(fmt.Sprintf(c.T("AuthErr.AuthStateWrong"), conf.GetConfigString("authState"), form.State))
c.ResponseError(fmt.Sprintf(c.T("auth:State expected: %s, but got: %s"), conf.GetConfigString("authState"), form.State))
return
}
@ -353,13 +353,13 @@ func (c *ApiController) Login() {
}
if !token.Valid() {
c.ResponseError(c.T("TokenErr.InvalidToken"))
c.ResponseError(c.T("auth:Invalid token"))
return
}
userInfo, err = idProvider.GetUserInfo(token)
if err != nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.LoginFail"), err.Error()))
c.ResponseError(fmt.Sprintf(c.T("auth:Failed to login in: %s"), err.Error()))
return
}
}
@ -376,7 +376,7 @@ func (c *ApiController) Login() {
// Sign in via OAuth (want to sign up but already have account)
if user.IsForbidden {
c.ResponseError(c.T("LoginErr.UserIsForbidden"))
c.ResponseError(c.T("auth:The user is forbidden to sign in, please contact the administrator"))
}
resp = c.HandleLoggedIn(application, user, &form)
@ -388,12 +388,12 @@ func (c *ApiController) Login() {
} else if provider.Category == "OAuth" {
// Sign up via OAuth
if !application.EnableSignUp {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppNotEnableSignUp"), provider.Type, userInfo.Username, userInfo.DisplayName))
c.ResponseError(fmt.Sprintf(c.T("auth:The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account, please contact your IT support"), provider.Type, userInfo.Username, userInfo.DisplayName))
return
}
if !providerItem.CanSignUp {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.ProviderCanNotSignUp"), provider.Type, userInfo.Username, userInfo.DisplayName, provider.Type))
c.ResponseError(fmt.Sprintf(c.T("auth:The account for provider: %s and username: %s (%s) does not exist and is not allowed to sign up as new account via %%s, please use another way to sign up"), provider.Type, userInfo.Username, userInfo.DisplayName, provider.Type))
return
}
@ -414,7 +414,7 @@ func (c *ApiController) Login() {
properties["no"] = strconv.Itoa(len(object.GetUsers(application.Organization)) + 2)
initScore, err := getInitScore()
if err != nil {
c.ResponseError(fmt.Errorf(c.T("InitErr.InitScoreFailed"), err).Error())
c.ResponseError(fmt.Errorf(c.T("auth:Get init score failed, error: %w"), err).Error())
return
}
@ -441,7 +441,7 @@ func (c *ApiController) Login() {
affected := object.AddUser(user)
if !affected {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.InvalidUserInformation"), util.StructToJson(user)))
c.ResponseError(fmt.Sprintf(c.T("auth:Failed to create user, user information is invalid: %s"), util.StructToJson(user)))
return
}
@ -466,13 +466,13 @@ func (c *ApiController) Login() {
} else { // form.Method != "signup"
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("LoginErr.AccountDoNotExist"), userInfo)
c.ResponseError(c.T("auth:The account does not exist"), userInfo)
return
}
oldUser := object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
if oldUser != nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.OldUser"), provider.Type, userInfo.Username, userInfo.DisplayName, oldUser.Name, oldUser.DisplayName))
c.ResponseError(fmt.Sprintf(c.T("auth:The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)"), provider.Type, userInfo.Username, userInfo.DisplayName, oldUser.Name, oldUser.DisplayName))
return
}
@ -493,7 +493,7 @@ func (c *ApiController) Login() {
// user already signed in to Casdoor, so let the user click the avatar button to do the quick sign-in
application := object.GetApplication(fmt.Sprintf("admin/%s", form.Application))
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.AppDoNotExist"), form.Application))
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), form.Application))
return
}
@ -505,7 +505,7 @@ func (c *ApiController) Login() {
record.User = user.Name
util.SafeGoroutine(func() { object.AddRecord(record) })
} else {
c.ResponseError(fmt.Sprintf(c.T("LoginErr.UnknownAuthentication"), util.StructToJson(form)))
c.ResponseError(fmt.Sprintf(c.T("auth:Unknown authentication type (not password or provider), form = %s"), util.StructToJson(form)))
return
}
}

View File

@ -210,7 +210,7 @@ func (c *RootController) SamlValidate() {
}
if !strings.HasPrefix(target, service) {
c.ResponseError(fmt.Sprintf(c.T("CasErr.ServiceDoNotMatch"), target, service))
c.ResponseError(fmt.Sprintf(c.T("cas:Service %s and %s do not match"), target, service))
return
}

View File

@ -47,7 +47,7 @@ func (c *ApiController) BatchEnforce() {
func (c *ApiController) GetAllObjects() {
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
c.ResponseError(c.T("enforcer:Please sign in first"))
return
}
@ -58,7 +58,7 @@ func (c *ApiController) GetAllObjects() {
func (c *ApiController) GetAllActions() {
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
c.ResponseError(c.T("enforcer:Please sign in first"))
return
}
@ -69,7 +69,7 @@ func (c *ApiController) GetAllActions() {
func (c *ApiController) GetAllRoles() {
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
c.ResponseError(c.T("enforcer:Please sign in first"))
return
}

View File

@ -52,7 +52,7 @@ func (c *ApiController) GetLdapUser() {
ldapServer := LdapServer{}
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldapServer)
if err != nil || util.IsStrsEmpty(ldapServer.Host, ldapServer.Admin, ldapServer.Passwd, ldapServer.BaseDn) {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("ldap:Missing parameter"))
return
}
@ -120,7 +120,7 @@ func (c *ApiController) GetLdap() {
id := c.Input().Get("id")
if util.IsStrsEmpty(id) {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("ldap:Missing parameter"))
return
}
@ -136,17 +136,17 @@ func (c *ApiController) AddLdap() {
var ldap object.Ldap
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
if err != nil {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("ldap:Missing parameter"))
return
}
if util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("ldap:Missing parameter"))
return
}
if object.CheckLdapExist(&ldap) {
c.ResponseError(c.T("LdapErr.ServerExisted"))
c.ResponseError(c.T("ldap:Ldap server exist"))
return
}
@ -171,7 +171,7 @@ func (c *ApiController) UpdateLdap() {
var ldap object.Ldap
err := json.Unmarshal(c.Ctx.Input.RequestBody, &ldap)
if err != nil || util.IsStrsEmpty(ldap.Owner, ldap.ServerName, ldap.Host, ldap.Admin, ldap.Passwd, ldap.BaseDn) {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("ldap:Missing parameter"))
return
}

View File

@ -47,7 +47,7 @@ func (c *ApiController) Unlink() {
if user.Id != unlinkedUser.Id && !user.IsGlobalAdmin {
// if the user is not the same as the one we are unlinking, we need to make sure the user is the global admin.
c.ResponseError(c.T("AuthErr.CanNotUnlinkUsers"))
c.ResponseError(c.T("link:You are not the global admin, you can't unlink other users"))
return
}
@ -55,23 +55,23 @@ func (c *ApiController) Unlink() {
// if the user is unlinking themselves, should check the provider can be unlinked, if not, we should return an error.
application := object.GetApplicationByUser(user)
if application == nil {
c.ResponseError(c.T("AuthErr.CanNotLinkMySelf"))
c.ResponseError(c.T("link:You can't unlink yourself, you are not a member of any application"))
return
}
if len(application.Providers) == 0 {
c.ResponseError(c.T("ApplicationErr.HasNoProviders"))
c.ResponseError(c.T("link:This application has no providers"))
return
}
provider := application.GetProviderItemByType(providerType)
if provider == nil {
c.ResponseError(c.T("ApplicationErr.HasNoProvidersOfType") + providerType)
c.ResponseError(c.T("link:This application has no providers of type") + providerType)
return
}
if !provider.CanUnlink {
c.ResponseError(c.T("ProviderErr.CanNotBeUnlinked"))
c.ResponseError(c.T("link:This provider can't be unlinked"))
return
}
@ -84,7 +84,7 @@ func (c *ApiController) Unlink() {
value := object.GetUserField(&unlinkedUser, providerType)
if value == "" {
c.ResponseError(c.T("ProviderErr.LinkFirstErr"), value)
c.ResponseError(c.T("link:Please link first"), value)
return
}

View File

@ -141,13 +141,13 @@ func (c *ApiController) BuyProduct() {
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("LoginErr.LoginFirst"))
c.ResponseError(c.T("product:Please login first"))
return
}
user := object.GetUser(userId)
if user == nil {
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId))
c.ResponseError(fmt.Sprintf(c.T("product:The user: %s doesn't exist"), userId))
return
}

View File

@ -154,7 +154,7 @@ func (c *ApiController) UploadResource() {
defer file.Close()
if username == "" || fullFilePath == "" {
c.ResponseError(fmt.Sprintf(c.T("ResourceErr.UsernameOrFilePathEmpty"), username, fullFilePath))
c.ResponseError(fmt.Sprintf(c.T("resource:Username or fullFilePath is empty: username = %s, fullFilePath = %s"), username, fullFilePath))
return
}
@ -227,7 +227,7 @@ func (c *ApiController) UploadResource() {
case "avatar":
user := object.GetUserNoCheck(util.GetId(owner, username))
if user == nil {
c.ResponseError(c.T("ResourceErr.UserIsNil"))
c.ResponseError(c.T("resource:User is nil for tag: avatar"))
return
}

View File

@ -25,7 +25,7 @@ func (c *ApiController) GetSamlMeta() {
paramApp := c.Input().Get("application")
application := object.GetApplication(paramApp)
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("ApplicationErr.AppNotFound"), paramApp))
c.ResponseError(fmt.Sprintf(c.T("saml:Application %s not found"), paramApp))
return
}
metadata, _ := object.GetSamlMeta(application, host)

View File

@ -81,7 +81,7 @@ func (c *ApiController) SendEmail() {
}
if util.IsStrsEmpty(emailForm.Title, emailForm.Content, emailForm.Sender) {
c.ResponseError(fmt.Sprintf(c.T("EmailErr.EmptyParam"), emailForm))
c.ResponseError(fmt.Sprintf(c.T("service:Empty parameters for emailForm: %v"), emailForm))
return
}
@ -93,7 +93,7 @@ func (c *ApiController) SendEmail() {
}
if len(invalidReceivers) != 0 {
c.ResponseError(fmt.Sprintf(c.T("EmailErr.InvalidReceivers"), invalidReceivers))
c.ResponseError(fmt.Sprintf(c.T("service:Invalid Email receivers: %s"), invalidReceivers))
return
}
@ -141,7 +141,7 @@ func (c *ApiController) SendSms() {
}
if len(invalidReceivers) != 0 {
c.ResponseError(fmt.Sprintf(c.T("PhoneErr.InvalidReceivers"), invalidReceivers))
c.ResponseError(fmt.Sprintf(c.T("service:Invalid phone receivers: %s"), invalidReceivers))
return
}

View File

@ -40,7 +40,7 @@ func (c *ApiController) GetSystemInfo() {
user := object.GetUser(id)
if user == nil || !user.IsGlobalAdmin {
c.ResponseError(c.T("ResourceErr.NotAuthorized"))
c.ResponseError(c.T("system_info:You are not authorized to access this resource"))
return
}

View File

@ -150,7 +150,7 @@ func (c *ApiController) GetOAuthCode() {
codeChallenge := c.Input().Get("code_challenge")
if challengeMethod != "S256" && challengeMethod != "null" && challengeMethod != "" {
c.ResponseError(c.T("AuthErr.ChallengeMethodErr"))
c.ResponseError(c.T("token:Challenge method should be S256"))
return
}
host := c.Ctx.Request.Host
@ -290,7 +290,7 @@ func (c *ApiController) IntrospectToken() {
clientId = c.Input().Get("client_id")
clientSecret = c.Input().Get("client_secret")
if clientId == "" || clientSecret == "" {
c.ResponseError(c.T("TokenErr.EmptyClientID"))
c.ResponseError(c.T("token:Empty clientId or clientSecret"))
c.Data["json"] = &object.TokenError{
Error: object.InvalidRequest,
}
@ -301,7 +301,7 @@ func (c *ApiController) IntrospectToken() {
}
application := object.GetApplicationByClientId(clientId)
if application == nil || application.ClientSecret != clientSecret {
c.ResponseError(c.T("TokenErr.InvalidAppOrWrongClientSecret"))
c.ResponseError(c.T("token:Invalid application or wrong clientSecret"))
c.Data["json"] = &object.TokenError{
Error: object.InvalidClient,
}

View File

@ -149,7 +149,7 @@ func (c *ApiController) UpdateUser() {
}
if user.DisplayName == "" {
c.ResponseError(c.T("UserErr.DisplayNameCanNotBeEmpty"))
c.ResponseError(c.T("user:Display name cannot be empty"))
return
}
@ -236,7 +236,7 @@ func (c *ApiController) GetEmailAndPhone() {
user := object.GetUserByFields(form.Organization, form.Username)
if user == nil {
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExistInOrg"), form.Organization, form.Username))
c.ResponseError(fmt.Sprintf(c.T("user:The user: %s/%s doesn't exist"), form.Organization, form.Username))
return
}
@ -294,12 +294,12 @@ func (c *ApiController) SetPassword() {
}
if strings.Contains(newPassword, " ") {
c.ResponseError(c.T("SetPasswordErr.CanNotContainBlank"))
c.ResponseError(c.T("user:New password cannot contain blank space."))
return
}
if len(newPassword) <= 5 {
c.ResponseError(c.T("SetPasswordErr.LessThanSixCharacters"))
c.ResponseError(c.T("user:New password must have at least 6 characters"))
return
}

View File

@ -61,6 +61,6 @@ func (c *ApiController) UploadUsers() {
if affected {
c.ResponseOk()
} else {
c.ResponseError(c.T("UserErr.FailToImportUsers"))
c.ResponseError(c.T("user_upload:Failed to import users"))
}
}

View File

@ -84,7 +84,7 @@ func (c *ApiController) SetTokenErrorHttpStatus() {
func (c *ApiController) RequireSignedIn() (string, bool) {
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError(c.T("LoginErr.LoginFirst"), "Please login first")
c.ResponseError(c.T("util:Please login first"), "util:Please login first")
return "", false
}
return userId, true
@ -100,7 +100,7 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
user := object.GetUser(userId)
if user == nil {
c.ClearUserSession()
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExist"), userId))
c.ResponseError(fmt.Sprintf(c.T("util:The user: %s doesn't exist"), userId))
return nil, false
}
return user, true
@ -128,7 +128,7 @@ func (c *ApiController) GetProviderFromContext(category string) (*object.Provide
if providerName != "" {
provider := object.GetProvider(util.GetId("admin", providerName))
if provider == nil {
c.ResponseError(c.T("ProviderErr.ProviderNotFound"), providerName)
c.ResponseError(c.T("util:The provider: %s is not found"), providerName)
return nil, nil, false
}
return provider, nil, true
@ -141,13 +141,13 @@ func (c *ApiController) GetProviderFromContext(category string) (*object.Provide
application, user := object.GetApplicationByUserId(userId)
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("ApplicationErr.AppNotFoundForUserID"), userId))
c.ResponseError(fmt.Sprintf(c.T("util:No application is found for userId: %s"), userId))
return nil, nil, false
}
provider := application.GetProviderByCategory(category)
if provider == nil {
c.ResponseError(fmt.Sprintf(c.T("ProviderErr.ProviderNotFoundForCategory"), category, application.Name))
c.ResponseError(fmt.Sprintf(c.T("util:No provider for category: %s is found for application: %s"), category, application.Name))
return nil, nil, false
}

View File

@ -50,23 +50,23 @@ func (c *ApiController) SendVerificationCode() {
remoteAddr := util.GetIPFromRequest(c.Ctx.Request)
if destType == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": type.")
c.ResponseError(c.T("verification:Missing parameter") + ": type.")
return
}
if dest == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": dest.")
c.ResponseError(c.T("verification:Missing parameter") + ": dest.")
return
}
if applicationId == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": applicationId.")
c.ResponseError(c.T("verification:Missing parameter") + ": applicationId.")
return
}
if !strings.Contains(applicationId, "/") {
c.ResponseError(c.T("ParameterErr.Wrong") + ": applicationId.")
c.ResponseError(c.T("verification:Wrong parameter") + ": applicationId.")
return
}
if checkType == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": checkType.")
c.ResponseError(c.T("verification:Missing parameter") + ": checkType.")
return
}
@ -74,7 +74,7 @@ func (c *ApiController) SendVerificationCode() {
if captchaProvider != nil {
if checkKey == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": checkKey.")
c.ResponseError(c.T("verification:Missing parameter") + ": checkKey.")
return
}
isHuman, err := captchaProvider.VerifyCaptcha(checkKey, checkId)
@ -84,7 +84,7 @@ func (c *ApiController) SendVerificationCode() {
}
if !isHuman {
c.ResponseError(c.T("AuthErr.NotHuman"))
c.ResponseError(c.T("verification:Turing test failed."))
return
}
}
@ -93,12 +93,12 @@ func (c *ApiController) SendVerificationCode() {
application := object.GetApplication(applicationId)
organization := object.GetOrganization(fmt.Sprintf("%s/%s", application.Owner, application.Organization))
if organization == nil {
c.ResponseError(c.T("OrgErr.DoNotExist"))
c.ResponseError(c.T("verification:Organization does not exist"))
return
}
if checkUser == "true" && user == nil && object.GetUserByFields(organization.Name, dest) == nil {
c.ResponseError(c.T("LoginErr.LoginFirst"))
c.ResponseError(c.T("verification:Please login first"))
return
}
@ -114,13 +114,13 @@ func (c *ApiController) SendVerificationCode() {
dest = user.Email
}
if !util.IsEmailValid(dest) {
c.ResponseError(c.T("EmailErr.EmailInvalid"))
c.ResponseError(c.T("verification:Email is invalid"))
return
}
userByEmail := object.GetUserByEmail(organization.Name, dest)
if userByEmail == nil {
c.ResponseError(c.T("UserErr.DoNotExistSignUp"))
c.ResponseError(c.T("verification:the user does not exist, please sign up first"))
return
}
@ -131,13 +131,13 @@ func (c *ApiController) SendVerificationCode() {
dest = user.Phone
}
if !util.IsPhoneCnValid(dest) {
c.ResponseError(c.T("PhoneErr.NumberInvalid"))
c.ResponseError(c.T("verification:Phone number is invalid"))
return
}
userByPhone := object.GetUserByPhone(organization.Name, dest)
if userByPhone == nil {
c.ResponseError(c.T("UserErr.DoNotExistSignUp"))
c.ResponseError(c.T("verification:the user does not exist, please sign up first"))
return
}
@ -169,7 +169,7 @@ func (c *ApiController) ResetEmailOrPhone() {
dest := c.Ctx.Request.Form.Get("dest")
code := c.Ctx.Request.Form.Get("code")
if len(dest) == 0 || len(code) == 0 || len(destType) == 0 {
c.ResponseError(c.T("ParameterErr.Missing"))
c.ResponseError(c.T("verification:Missing parameter"))
return
}
@ -178,7 +178,7 @@ func (c *ApiController) ResetEmailOrPhone() {
if destType == "phone" {
phoneItem := object.GetAccountItemByName("Phone", org)
if phoneItem == nil {
c.ResponseError(c.T("PhoneErr.UnableGetModifyRule"))
c.ResponseError(c.T("verification:Unable to get the phone modify rule."))
return
}
@ -195,7 +195,7 @@ func (c *ApiController) ResetEmailOrPhone() {
} else if destType == "email" {
emailItem := object.GetAccountItemByName("Email", org)
if emailItem == nil {
c.ResponseError(c.T("EmailErr.UnableGetModifyRule"))
c.ResponseError(c.T("verification:Unable to get the email modify rule."))
return
}
@ -217,7 +217,7 @@ func (c *ApiController) ResetEmailOrPhone() {
user.Phone = dest
object.SetUserField(user, "phone", user.Phone)
default:
c.ResponseError(c.T("ParameterErr.UnknownType"))
c.ResponseError(c.T("verification:Unknown type"))
return
}
@ -236,17 +236,17 @@ func (c *ApiController) VerifyCaptcha() {
captchaToken := c.Ctx.Request.Form.Get("captchaToken")
clientSecret := c.Ctx.Request.Form.Get("clientSecret")
if captchaToken == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": captchaToken.")
c.ResponseError(c.T("verification:Missing parameter") + ": captchaToken.")
return
}
if clientSecret == "" {
c.ResponseError(c.T("ParameterErr.Missing") + ": clientSecret.")
c.ResponseError(c.T("verification:Missing parameter") + ": clientSecret.")
return
}
provider := captcha.GetCaptchaProvider(captchaType)
if provider == nil {
c.ResponseError(c.T("ProviderErr.InvalidProvider"))
c.ResponseError(c.T("verification:Invalid captcha provider."))
return
}

View File

@ -35,7 +35,7 @@ func (c *ApiController) WebAuthnSignupBegin() {
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
user := c.getCurrentUser()
if user == nil {
c.ResponseError(c.T("LoginErr.LoginFirst"))
c.ResponseError(c.T("webauthn:Please login first"))
return
}
@ -66,13 +66,13 @@ func (c *ApiController) WebAuthnSignupFinish() {
webauthnObj := object.GetWebAuthnObject(c.Ctx.Request.Host)
user := c.getCurrentUser()
if user == nil {
c.ResponseError(c.T("LoginErr.LoginFirst"))
c.ResponseError(c.T("webauthn:Please login first"))
return
}
sessionObj := c.GetSession("registration")
sessionData, ok := sessionObj.(webauthn.SessionData)
if !ok {
c.ResponseError(c.T("AuthErr.CallWebAuthnSigninBegin"))
c.ResponseError(c.T("webauthn:Please call WebAuthnSigninBegin first"))
return
}
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
@ -101,11 +101,11 @@ func (c *ApiController) WebAuthnSigninBegin() {
userName := c.Input().Get("name")
user := object.GetUserByFields(userOwner, userName)
if user == nil {
c.ResponseError(fmt.Sprintf(c.T("UserErr.DoNotExistInOrg"), userOwner, userName))
c.ResponseError(fmt.Sprintf(c.T("webauthn:The user: %s/%s doesn't exist"), userOwner, userName))
return
}
if len(user.WebauthnCredentials) == 0 {
c.ResponseError(c.T("UserErr.NoWebAuthnCredential"))
c.ResponseError(c.T("webauthn:Found no credentials for this user"))
return
}
@ -132,7 +132,7 @@ func (c *ApiController) WebAuthnSigninFinish() {
sessionObj := c.GetSession("authentication")
sessionData, ok := sessionObj.(webauthn.SessionData)
if !ok {
c.ResponseError(c.T("AuthErr.CallWebAuthnSigninBegin"))
c.ResponseError(c.T("webauthn:Please call WebAuthnSigninBegin first"))
return
}
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))