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): add user center email auth check
LinkinStars86685202ac84
diff --git a/internal/controller/plugin_user_center_controller.go b/internal/controller/plugin_user_center_controller.goindex b8160f72..231cdecd 100644--- a/internal/controller/plugin_user_center_controller.go+++ b/internal/controller/plugin_user_center_controller.go@@ -3,8 +3,6 @@ package controllerimport ("fmt""net/http"- "net/url"- "strings""github.com/answerdev/answer/internal/base/handler""github.com/answerdev/answer/internal/base/middleware"@@ -126,7 +124,9 @@ func (uc *UserCenterController) UserCenterLoginCallback(ctx *gin.Context) {userInfo, err := userCenter.LoginCallback(ctx)if err != nil {log.Error(err)- ctx.Redirect(http.StatusFound, "/50x")+ if !ctx.IsAborted() {+ ctx.Redirect(http.StatusFound, "/50x")+ }return}@@ -192,17 +192,3 @@ func (uc *UserCenterController) UserCenterAdminFunctionAgent(ctx *gin.Context) {resp, err := uc.userCenterLoginService.UserCenterAdminFunctionAgent(ctx)handler.HandleResponse(ctx, err, resp)}--func (uc *UserCenterController) formatRedirectURL(ctx *gin.Context, redirectURL string) string {- if !strings.Contains(redirectURL, "CALLBACK_URL") {- return redirectURL- }- general, err := uc.siteInfoService.GetSiteGeneral(ctx)- if err != nil {- log.Error(err)- ctx.Redirect(http.StatusFound, "/50x")- return ""- }- callbackURL := fmt.Sprintf("%s%s%s", general.SiteUrl, commonRouterPrefix, "/user-center/login/callback")- return strings.ReplaceAll(redirectURL, "CALLBACK_URL", url.QueryEscape(callbackURL))-}diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.goindex b5cee0c4..8727267f 100644--- a/internal/repo/user/user_repo.go+++ b/internal/repo/user/user_repo.go@@ -290,8 +290,7 @@ func decorateByUserCenterUser(original *entity.User, ucUser *plugin.UserCenterBaoriginal.Mobile = ucUser.Mobile}if len(ucUser.Bio) > 0 {- original.Bio = ucUser.Bio- original.BioHTML = converter.Markdown2HTML(ucUser.Bio)+ original.BioHTML = converter.Markdown2HTML(ucUser.Bio) + original.BioHTML}// If plugin enable rank agent, use rank from user center.diff --git a/internal/schema/plugin_admin_schema.go b/internal/schema/plugin_admin_schema.goindex be63d3ab..6758fb00 100644--- a/internal/schema/plugin_admin_schema.go+++ b/internal/schema/plugin_admin_schema.go@@ -60,6 +60,12 @@ func (g *GetPluginConfigResp) SetConfigFields(ctx *gin.Context, fields []plugin.}configField.UIOptions.Placeholder = field.UIOptions.Placeholder.Translate(ctx)configField.UIOptions.Label = field.UIOptions.Label.Translate(ctx)+ configField.UIOptions.Text = field.UIOptions.Text.Translate(ctx)+ if field.UIOptions.Action != nil {+ configField.UIOptions.Action = &ConfigFieldUIOptionAction{+ Url: field.UIOptions.Action.Url,+ }+ }for _, option := range field.Options {configField.Options = append(configField.Options, ConfigFieldOption{@@ -83,10 +89,12 @@ type ConfigField struct {}type ConfigFieldUIOptions struct {- Placeholder string `json:"placeholder,omitempty"`- Rows string `json:"rows,omitempty"`- InputType string `json:"input_type,omitempty"`- Label string `json:"label,omitempty"`+ Placeholder string `json:"placeholder,omitempty"`+ Rows string `json:"rows,omitempty"`+ InputType string `json:"input_type,omitempty"`+ Label string `json:"label,omitempty"`+ Action *ConfigFieldUIOptionAction `json:"action,omitempty"`+ Text string `json:"text,omitempty"`}type ConfigFieldOption struct {@@ -94,6 +102,10 @@ type ConfigFieldOption struct {Value string `json:"value"`}+type ConfigFieldUIOptionAction struct {+ Url string `json:"url"`+}+type UpdatePluginConfigReq struct {PluginSlugName string `validate:"required,gt=1,lte=100" json:"plugin_slug_name"`ConfigFields map[string]any `json:"config_fields"`diff --git a/internal/service/user_external_login/user_center_login_service.go b/internal/service/user_external_login/user_center_login_service.goindex 307590c8..0d3ccf43 100644--- a/internal/service/user_external_login/user_center_login_service.go+++ b/internal/service/user_external_login/user_center_login_service.go@@ -14,6 +14,7 @@ import ("github.com/answerdev/answer/internal/service/siteinfo_common"usercommon "github.com/answerdev/answer/internal/service/user_common""github.com/answerdev/answer/pkg/checker"+ "github.com/answerdev/answer/pkg/converter""github.com/answerdev/answer/pkg/random""github.com/answerdev/answer/plugin""github.com/segmentfault/pacman/log"@@ -85,7 +86,6 @@ func (us *UserCenterLoginService) ExternalLogin(// cache external user info, waiting for user enter email address.if userCenter.Description().MustAuthEmailEnabled && len(basicUserInfo.Email) == 0 {- // TODO: checkreturn &schema.UserExternalLoginResp{ErrMsg: "Requires authorized email to login"}, nil}@@ -126,7 +126,7 @@ func (us *UserCenterLoginService) registerNewUser(ctx context.Context, provideruserInfo.Status = entity.UserStatusAvailableuserInfo.LastLoginDate = time.Now()userInfo.Bio = basicUserInfo.Bio- userInfo.BioHTML = basicUserInfo.Bio+ userInfo.BioHTML = converter.Markdown2HTML(basicUserInfo.Bio)err = us.userRepo.AddUser(ctx, userInfo)if err != nil {return nil, errdiff --git a/plugin/config.go b/plugin/config.goindex d7c25cae..cae8ac31 100644--- a/plugin/config.go+++ b/plugin/config.go@@ -12,6 +12,7 @@ const (ConfigTypeUpload ConfigType = "upload"ConfigTypeTimezone ConfigType = "timezone"ConfigTypeSwitch ConfigType = "switch"+ ConfigTypeButton ConfigType = "button")const (@@ -43,10 +44,12 @@ type ConfigField struct {}type ConfigFieldUIOptions struct {- Placeholder Translator `json:"placeholder,omitempty"`- Rows string `json:"rows,omitempty"`- InputType InputType `json:"input_type,omitempty"`- Label Translator `json:"label,omitempty"`+ Placeholder Translator `json:"placeholder,omitempty"`+ Rows string `json:"rows,omitempty"`+ InputType InputType `json:"input_type,omitempty"`+ Label Translator `json:"label,omitempty"`+ Action *ConfigFieldUIOptionAction `json:"action,omitempty"`+ Text Translator `json:"text,omitempty"`}type ConfigFieldOption struct {@@ -54,6 +57,10 @@ type ConfigFieldOption struct {Value string `json:"value"`}+type ConfigFieldUIOptionAction struct {+ Url string `json:"url"`+}+type Config interface {Base