Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(usercenter): plugin user center add i18n

LinkinStarsaf08b3e392e1
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index e3585d51..09f965ab 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -51,7 +51,7 @@ backend:
privilege:
level_1:
description:
- other: Level 1 (less reputation required for startup community)
+ other: Level 1 (less reputation required for private team, group)
level_2:
description:
other: Level 2 (low reputation required for startup community)
@@ -140,7 +140,7 @@ backend:
verify_url_expired:
other: Email verified URL has expired, please resend the email.
illegal_email_domain_error:
- other: The domain name of the current email address cannot be registered.
+ other: Email is not allowed from that email domain. Please use another one.
lang:
not_found:
other: Language file not found.
@@ -232,6 +232,10 @@ backend:
other: You cannot modify your role.
not_allowed_registration:
other: Currently the site is not open for registration
+ access_denied:
+ other: Access denied
+ page_access_denied:
+ other: You do not have access to this page.
config:
read_config_failed:
other: Read config failed
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index 66e9ebd6..eefea665 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -136,6 +136,8 @@ backend:
other: 邮箱需要验证。
verify_url_expired:
other: 邮箱验证的网址已过期,请重新发送邮件。
+ illegal_email_domain_error:
+ other: 该域名的邮箱无法使用。请尝试更换其他邮箱。
lang:
not_found:
other: 语言未找到
@@ -225,6 +227,10 @@ backend:
other: 您不能修改自己的角色。
not_allowed_registration:
other: 目前该站点未开放注册
+ access_denied:
+ other: 访问被拒绝
+ page_access_denied:
+ other: 你没有权限进入这个页面。
config:
read_config_failed:
other: 读取配置失败
@@ -1112,6 +1118,9 @@ ui:
installed_plugins: 插件列表
website_welcome: 欢迎来到 {{site_name}}
plugins:
+ login: 登录
+ qrcode_login_tip: 请使用 {{ agentName }} 扫描二维码登录
+ login_failed_email_tip: 登录失败, 请允许该应用程序访问您的电子邮件信息,然后再试一次。
oauth:
connect: 连接到 {{ auth_name }}
remove: 解绑 {{ auth_name }}
diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go
index 814bda95..3c257944 100644
--- a/internal/base/reason/reason.go
+++ b/internal/base/reason/reason.go
@@ -74,4 +74,6 @@ const (
AdminCannotUpdateTheirPassword = "error.admin.cannot_update_their_password"
AdminCannotModifySelfStatus = "error.admin.cannot_modify_self_status"
UserExternalLoginUnbindingForbidden = "error.user.external_login_unbinding_forbidden"
+ UserAccessDenied = "error.user.access_denied"
+ UserPageAccessDenied = "error.user.page_access_denied"
)
diff --git a/internal/controller/plugin_user_center_controller.go b/internal/controller/plugin_user_center_controller.go
index 23a8df57..024a0692 100644
--- a/internal/controller/plugin_user_center_controller.go
+++ b/internal/controller/plugin_user_center_controller.go
@@ -60,6 +60,7 @@ func (uc *UserCenterController) UserCenterAgent(ctx *gin.Context) {
_ = plugin.CallUserCenter(func(uc plugin.UserCenter) error {
info := uc.Description()
resp.AgentInfo.Name = info.Name
+ resp.AgentInfo.DisplayName = info.DisplayName.Translate(ctx)
resp.AgentInfo.Icon = info.Icon
resp.AgentInfo.Url = info.Url
resp.AgentInfo.ControlCenterItems = make([]*schema.ControlCenter, 0)
@@ -138,7 +139,7 @@ func (uc *UserCenterController) UserCenterLoginCallback(ctx *gin.Context) {
return
}
if len(resp.ErrMsg) > 0 {
- ctx.Redirect(http.StatusFound, "/50x?msg="+resp.ErrMsg)
+ ctx.Redirect(http.StatusFound, fmt.Sprintf("/50x?title=%s&msg=%s", resp.ErrTitle, resp.ErrMsg))
return
}
userCenter.AfterLogin(userInfo.ExternalID, resp.AccessToken)
@@ -173,7 +174,7 @@ func (uc *UserCenterController) UserCenterSignUpCallback(ctx *gin.Context) {
return
}
if len(resp.ErrMsg) > 0 {
- ctx.Redirect(http.StatusFound, "/50x?msg="+resp.ErrMsg)
+ ctx.Redirect(http.StatusFound, fmt.Sprintf("/50x?title=%s&msg=%s", resp.ErrTitle, resp.ErrMsg))
return
}
userCenter.AfterLogin(userInfo.ExternalID, resp.AccessToken)
diff --git a/internal/schema/plugin_admin_schema.go b/internal/schema/plugin_admin_schema.go
index 6758fb00..3ea8aeab 100644
--- a/internal/schema/plugin_admin_schema.go
+++ b/internal/schema/plugin_admin_schema.go
@@ -56,6 +56,7 @@ func (g *GetPluginConfigResp) SetConfigFields(ctx *gin.Context, fields []plugin.
UIOptions: ConfigFieldUIOptions{
Rows: field.UIOptions.Rows,
InputType: string(field.UIOptions.InputType),
+ Variant: field.UIOptions.Variant,
},
}
configField.UIOptions.Placeholder = field.UIOptions.Placeholder.Translate(ctx)
@@ -94,6 +95,7 @@ type ConfigFieldUIOptions struct {
InputType string `json:"input_type,omitempty"`
Label string `json:"label,omitempty"`
Action *ConfigFieldUIOptionAction `json:"action,omitempty"`
+ Variant string `json:"variant,omitempty"`
Text string `json:"text,omitempty"`
}
diff --git a/internal/schema/plugin_user_center.go b/internal/schema/plugin_user_center.go
index a9d0e0d3..9a5f65a8 100644
--- a/internal/schema/plugin_user_center.go
+++ b/internal/schema/plugin_user_center.go
@@ -7,6 +7,7 @@ type UserCenterAgentResp struct {
type AgentInfo struct {
Name string `json:"name"`
+ DisplayName string `json:"display_name"`
Icon string `json:"icon"`
Url string `json:"url"`
LoginRedirectURL string `json:"login_redirect_url"`
diff --git a/internal/schema/user_external_login_schema.go b/internal/schema/user_external_login_schema.go
index 0998aea7..221ff17f 100644
--- a/internal/schema/user_external_login_schema.go
+++ b/internal/schema/user_external_login_schema.go
@@ -5,7 +5,8 @@ type UserExternalLoginResp struct {
BindingKey string `json:"binding_key"`
AccessToken string `json:"access_token"`
// ErrMsg error message, if not empty, means login failed and this message should be displayed.
- ErrMsg string `json:"-"`
+ ErrMsg string `json:"-"`
+ ErrTitle string `json:"-"`
}
// ExternalLoginBindingUserSendEmailReq external login binding user request
diff --git a/internal/service/user_external_login/user_center_login_service.go b/internal/service/user_external_login/user_center_login_service.go
index 6bf50fae..773196e9 100644
--- a/internal/service/user_external_login/user_center_login_service.go
+++ b/internal/service/user_external_login/user_center_login_service.go
@@ -59,7 +59,9 @@ func (us *UserCenterLoginService) ExternalLogin(
if !checker.EmailInAllowEmailDomain(basicUserInfo.Email, siteInfo.AllowEmailDomains) {
log.Debugf("email domain not allowed: %s", basicUserInfo.Email)
return &schema.UserExternalLoginResp{
- ErrMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.EmailIllegalDomainError)}, nil
+ ErrTitle: translator.Tr(handler.GetLangByCtx(ctx), reason.UserAccessDenied),
+ ErrMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.EmailIllegalDomainError),
+ }, nil
}
}
@@ -75,6 +77,13 @@ func (us *UserCenterLoginService) ExternalLogin(
return nil, err
}
if exist {
+ // if user is deleted, do not allow login
+ if oldUserInfo.Status == entity.UserStatusDeleted {
+ return &schema.UserExternalLoginResp{
+ ErrTitle: translator.Tr(handler.GetLangByCtx(ctx), reason.UserAccessDenied),
+ ErrMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.UserPageAccessDenied),
+ }, nil
+ }
if err := us.userRepo.UpdateLastLoginDate(ctx, oldUserInfo.ID); err != nil {
log.Errorf("update user last login date failed: %v", err)
}
diff --git a/plugin/config.go b/plugin/config.go
index cae8ac31..856c71ec 100644
--- a/plugin/config.go
+++ b/plugin/config.go
@@ -49,6 +49,7 @@ type ConfigFieldUIOptions struct {
InputType InputType `json:"input_type,omitempty"`
Label Translator `json:"label,omitempty"`
Action *ConfigFieldUIOptionAction `json:"action,omitempty"`
+ Variant string `json:"variant,omitempty"`
Text Translator `json:"text,omitempty"`
}
diff --git a/plugin/user_center.go b/plugin/user_center.go
index 6c963e24..57061394 100644
--- a/plugin/user_center.go
+++ b/plugin/user_center.go
@@ -25,15 +25,16 @@ type UserCenter interface {
}
type UserCenterDesc struct {
- Name string `json:"name"`
- Icon string `json:"icon"`
- Url string `json:"url"`
- LoginRedirectURL string `json:"login_redirect_url"`
- SignUpRedirectURL string `json:"sign_up_redirect_url"`
- RankAgentEnabled bool `json:"rank_agent_enabled"`
- UserStatusAgentEnabled bool `json:"user_status_agent_enabled"`
- MustAuthEmailEnabled bool `json:"must_auth_email_enabled"`
- EnabledOriginalUserSystem bool `json:"enabled_original_user_system"`
+ Name string `json:"name"`
+ DisplayName Translator `json:"display_name"`
+ Icon string `json:"icon"`
+ Url string `json:"url"`
+ LoginRedirectURL string `json:"login_redirect_url"`
+ SignUpRedirectURL string `json:"sign_up_redirect_url"`
+ RankAgentEnabled bool `json:"rank_agent_enabled"`
+ UserStatusAgentEnabled bool `json:"user_status_agent_enabled"`
+ MustAuthEmailEnabled bool `json:"must_auth_email_enabled"`
+ EnabledOriginalUserSystem bool `json:"enabled_original_user_system"`
}
type UserStatus int