feat(usercenter): plugin user center add i18n

This commit is contained in:
LinkinStars 2023-04-20 19:10:24 +08:00
parent 3c96abfcc5
commit af08b3e392
10 changed files with 46 additions and 15 deletions

View File

@ -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

View File

@ -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 }}

View File

@ -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"
)

View File

@ -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)

View File

@ -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"`
}

View File

@ -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"`

View File

@ -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

View File

@ -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)
}

View File

@ -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"`
}

View File

@ -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