diff --git a/docs/docs.go b/docs/docs.go index f371483a..616e5c28 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1301,6 +1301,77 @@ const docTemplate = `{ } } }, + "/answer/admin/api/siteinfo/users": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get site user config", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get site user config", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteUsersResp" + } + } + } + ] + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update site info config about users", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update site info config about users", + "parameters": [ + { + "description": "users info", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.SiteUsersReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/siteinfo/write": { "get": { "security": [ @@ -6149,12 +6220,21 @@ const docTemplate = `{ } } }, - "schema.ConfigFields": { + "schema.ConfigField": { "type": "object", "properties": { "description": { "type": "string" }, + "name": { + "type": "string" + }, + "options": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.ConfigFieldOption" + } + }, "required": { "type": "boolean" }, @@ -6164,14 +6244,40 @@ const docTemplate = `{ "type": { "type": "string" }, - "ui_widget": { - "$ref": "#/definitions/schema.UIWidget" + "ui_options": { + "$ref": "#/definitions/schema.ConfigFieldUIOptions" + }, + "value": {} + } + }, + "schema.ConfigFieldOption": { + "type": "object", + "properties": { + "label": { + "type": "string" }, "value": { "type": "string" } } }, + "schema.ConfigFieldUIOptions": { + "type": "object", + "properties": { + "input_type": { + "type": "string" + }, + "label": { + "type": "string" + }, + "placeholder": { + "type": "string" + }, + "rows": { + "type": "string" + } + } + }, "schema.ConnectorInfoResp": { "type": "object", "properties": { @@ -6532,14 +6638,13 @@ const docTemplate = `{ "config_fields": { "type": "array", "items": { - "$ref": "#/definitions/schema.ConfigFields" + "$ref": "#/definitions/schema.ConfigField" } }, "description": { "type": "string" }, "name": { - "description": "ConfigFields []plugin.ConfigField ` + "`" + `json:\"config_fields\"` + "`" + `", "type": "string" }, "slug_name": { @@ -6562,6 +6667,9 @@ const docTemplate = `{ "have_config": { "type": "boolean" }, + "link": { + "type": "string" + }, "name": { "type": "string" }, @@ -7009,6 +7117,10 @@ const docTemplate = `{ "description": "follow count", "type": "integer" }, + "have_password": { + "description": "user have password", + "type": "boolean" + }, "id": { "description": "user id", "type": "string" @@ -7109,6 +7221,9 @@ const docTemplate = `{ "description": "follow count", "type": "integer" }, + "have_password": { + "type": "boolean" + }, "id": { "description": "user id", "type": "string" @@ -7802,6 +7917,9 @@ const docTemplate = `{ "site_seo": { "$ref": "#/definitions/schema.SiteSeoReq" }, + "site_users": { + "$ref": "#/definitions/schema.SiteUsersResp" + }, "theme": { "$ref": "#/definitions/schema.SiteThemeResp" }, @@ -7897,6 +8015,15 @@ const docTemplate = `{ "schema.SiteLoginReq": { "type": "object", "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, "allow_new_registrations": { "type": "boolean" }, @@ -7908,6 +8035,15 @@ const docTemplate = `{ "schema.SiteLoginResp": { "type": "object", "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, "allow_new_registrations": { "type": "boolean" }, @@ -7984,6 +8120,72 @@ const docTemplate = `{ } } }, + "schema.SiteUsersReq": { + "type": "object", + "required": [ + "default_avatar" + ], + "properties": { + "allow_update_avatar": { + "type": "boolean" + }, + "allow_update_bio": { + "type": "boolean" + }, + "allow_update_display_name": { + "type": "boolean" + }, + "allow_update_location": { + "type": "boolean" + }, + "allow_update_username": { + "type": "boolean" + }, + "allow_update_website": { + "type": "boolean" + }, + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] + } + } + }, + "schema.SiteUsersResp": { + "type": "object", + "required": [ + "default_avatar" + ], + "properties": { + "allow_update_avatar": { + "type": "boolean" + }, + "allow_update_bio": { + "type": "boolean" + }, + "allow_update_display_name": { + "type": "boolean" + }, + "allow_update_location": { + "type": "boolean" + }, + "allow_update_username": { + "type": "boolean" + }, + "allow_update_website": { + "type": "boolean" + }, + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] + } + } + }, "schema.SiteWriteReq": { "type": "object", "properties": { @@ -8096,17 +8298,6 @@ const docTemplate = `{ } } }, - "schema.UIWidget": { - "type": "object", - "properties": { - "placeholder": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "schema.UnreviewedRevisionInfoInfo": { "type": "object", "properties": { @@ -8493,14 +8684,19 @@ const docTemplate = `{ }, "schema.UserModifyPassWordRequest": { "type": "object", + "required": [ + "pass" + ], "properties": { "old_pass": { - "description": "old password", - "type": "string" + "type": "string", + "maxLength": 32, + "minLength": 8 }, "pass": { - "description": "password", - "type": "string" + "type": "string", + "maxLength": 32, + "minLength": 8 } } }, diff --git a/docs/swagger.json b/docs/swagger.json index 235fa4d7..d015d8c2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1289,6 +1289,77 @@ } } }, + "/answer/admin/api/siteinfo/users": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get site user config", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "get site user config", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SiteUsersResp" + } + } + } + ] + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update site info config about users", + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "update site info config about users", + "parameters": [ + { + "description": "users info", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.SiteUsersReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/siteinfo/write": { "get": { "security": [ @@ -6137,12 +6208,21 @@ } } }, - "schema.ConfigFields": { + "schema.ConfigField": { "type": "object", "properties": { "description": { "type": "string" }, + "name": { + "type": "string" + }, + "options": { + "type": "array", + "items": { + "$ref": "#/definitions/schema.ConfigFieldOption" + } + }, "required": { "type": "boolean" }, @@ -6152,14 +6232,40 @@ "type": { "type": "string" }, - "ui_widget": { - "$ref": "#/definitions/schema.UIWidget" + "ui_options": { + "$ref": "#/definitions/schema.ConfigFieldUIOptions" + }, + "value": {} + } + }, + "schema.ConfigFieldOption": { + "type": "object", + "properties": { + "label": { + "type": "string" }, "value": { "type": "string" } } }, + "schema.ConfigFieldUIOptions": { + "type": "object", + "properties": { + "input_type": { + "type": "string" + }, + "label": { + "type": "string" + }, + "placeholder": { + "type": "string" + }, + "rows": { + "type": "string" + } + } + }, "schema.ConnectorInfoResp": { "type": "object", "properties": { @@ -6520,14 +6626,13 @@ "config_fields": { "type": "array", "items": { - "$ref": "#/definitions/schema.ConfigFields" + "$ref": "#/definitions/schema.ConfigField" } }, "description": { "type": "string" }, "name": { - "description": "ConfigFields []plugin.ConfigField `json:\"config_fields\"`", "type": "string" }, "slug_name": { @@ -6550,6 +6655,9 @@ "have_config": { "type": "boolean" }, + "link": { + "type": "string" + }, "name": { "type": "string" }, @@ -6997,6 +7105,10 @@ "description": "follow count", "type": "integer" }, + "have_password": { + "description": "user have password", + "type": "boolean" + }, "id": { "description": "user id", "type": "string" @@ -7097,6 +7209,9 @@ "description": "follow count", "type": "integer" }, + "have_password": { + "type": "boolean" + }, "id": { "description": "user id", "type": "string" @@ -7790,6 +7905,9 @@ "site_seo": { "$ref": "#/definitions/schema.SiteSeoReq" }, + "site_users": { + "$ref": "#/definitions/schema.SiteUsersResp" + }, "theme": { "$ref": "#/definitions/schema.SiteThemeResp" }, @@ -7885,6 +8003,15 @@ "schema.SiteLoginReq": { "type": "object", "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, "allow_new_registrations": { "type": "boolean" }, @@ -7896,6 +8023,15 @@ "schema.SiteLoginResp": { "type": "object", "properties": { + "allow_email_domains": { + "type": "array", + "items": { + "type": "string" + } + }, + "allow_email_registrations": { + "type": "boolean" + }, "allow_new_registrations": { "type": "boolean" }, @@ -7972,6 +8108,72 @@ } } }, + "schema.SiteUsersReq": { + "type": "object", + "required": [ + "default_avatar" + ], + "properties": { + "allow_update_avatar": { + "type": "boolean" + }, + "allow_update_bio": { + "type": "boolean" + }, + "allow_update_display_name": { + "type": "boolean" + }, + "allow_update_location": { + "type": "boolean" + }, + "allow_update_username": { + "type": "boolean" + }, + "allow_update_website": { + "type": "boolean" + }, + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] + } + } + }, + "schema.SiteUsersResp": { + "type": "object", + "required": [ + "default_avatar" + ], + "properties": { + "allow_update_avatar": { + "type": "boolean" + }, + "allow_update_bio": { + "type": "boolean" + }, + "allow_update_display_name": { + "type": "boolean" + }, + "allow_update_location": { + "type": "boolean" + }, + "allow_update_username": { + "type": "boolean" + }, + "allow_update_website": { + "type": "boolean" + }, + "default_avatar": { + "type": "string", + "enum": [ + "system", + "gravatar" + ] + } + } + }, "schema.SiteWriteReq": { "type": "object", "properties": { @@ -8084,17 +8286,6 @@ } } }, - "schema.UIWidget": { - "type": "object", - "properties": { - "placeholder": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "schema.UnreviewedRevisionInfoInfo": { "type": "object", "properties": { @@ -8481,14 +8672,19 @@ }, "schema.UserModifyPassWordRequest": { "type": "object", + "required": [ + "pass" + ], "properties": { "old_pass": { - "description": "old password", - "type": "string" + "type": "string", + "maxLength": 32, + "minLength": 8 }, "pass": { - "description": "password", - "type": "string" + "type": "string", + "maxLength": 32, + "minLength": 8 } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c6c02c1a..7010d1f3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -305,21 +305,44 @@ definitions: switch: type: boolean type: object - schema.ConfigFields: + schema.ConfigField: properties: description: type: string + name: + type: string + options: + items: + $ref: '#/definitions/schema.ConfigFieldOption' + type: array required: type: boolean title: type: string type: type: string - ui_widget: - $ref: '#/definitions/schema.UIWidget' + ui_options: + $ref: '#/definitions/schema.ConfigFieldUIOptions' + value: {} + type: object + schema.ConfigFieldOption: + properties: + label: + type: string value: type: string type: object + schema.ConfigFieldUIOptions: + properties: + input_type: + type: string + label: + type: string + placeholder: + type: string + rows: + type: string + type: object schema.ConnectorInfoResp: properties: icon: @@ -580,12 +603,11 @@ definitions: properties: config_fields: items: - $ref: '#/definitions/schema.ConfigFields' + $ref: '#/definitions/schema.ConfigField' type: array description: type: string name: - description: ConfigFields []plugin.ConfigField `json:"config_fields"` type: string slug_name: type: string @@ -600,6 +622,8 @@ definitions: type: boolean have_config: type: boolean + link: + type: string name: type: string slug_name: @@ -920,6 +944,9 @@ definitions: follow_count: description: follow count type: integer + have_password: + description: user have password + type: boolean id: description: user id type: string @@ -994,6 +1021,8 @@ definitions: follow_count: description: follow count type: integer + have_password: + type: boolean id: description: user id type: string @@ -1485,6 +1514,8 @@ definitions: type: string site_seo: $ref: '#/definitions/schema.SiteSeoReq' + site_users: + $ref: '#/definitions/schema.SiteUsersResp' theme: $ref: '#/definitions/schema.SiteThemeResp' version: @@ -1550,6 +1581,12 @@ definitions: type: object schema.SiteLoginReq: properties: + allow_email_domains: + items: + type: string + type: array + allow_email_registrations: + type: boolean allow_new_registrations: type: boolean login_required: @@ -1557,6 +1594,12 @@ definitions: type: object schema.SiteLoginResp: properties: + allow_email_domains: + items: + type: string + type: array + allow_email_registrations: + type: boolean allow_new_registrations: type: boolean login_required: @@ -1609,6 +1652,50 @@ definitions: $ref: '#/definitions/schema.ThemeOption' type: array type: object + schema.SiteUsersReq: + properties: + allow_update_avatar: + type: boolean + allow_update_bio: + type: boolean + allow_update_display_name: + type: boolean + allow_update_location: + type: boolean + allow_update_username: + type: boolean + allow_update_website: + type: boolean + default_avatar: + enum: + - system + - gravatar + type: string + required: + - default_avatar + type: object + schema.SiteUsersResp: + properties: + allow_update_avatar: + type: boolean + allow_update_bio: + type: boolean + allow_update_display_name: + type: boolean + allow_update_location: + type: boolean + allow_update_username: + type: boolean + allow_update_website: + type: boolean + default_avatar: + enum: + - system + - gravatar + type: string + required: + - default_avatar + type: object schema.SiteWriteReq: properties: recommend_tags: @@ -1687,13 +1774,6 @@ definitions: value: type: string type: object - schema.UIWidget: - properties: - placeholder: - type: string - type: - type: string - type: object schema.UnreviewedRevisionInfoInfo: properties: content: @@ -1971,11 +2051,15 @@ definitions: schema.UserModifyPassWordRequest: properties: old_pass: - description: old password + maxLength: 32 + minLength: 8 type: string pass: - description: password + maxLength: 32 + minLength: 8 type: string + required: + - pass type: object schema.UserNoticeSetRequest: properties: @@ -2881,6 +2965,47 @@ paths: summary: update site custom css html config tags: - admin + /answer/admin/api/siteinfo/users: + get: + description: get site user config + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SiteUsersResp' + type: object + security: + - ApiKeyAuth: [] + summary: get site user config + tags: + - admin + put: + description: update site info config about users + parameters: + - description: users info + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.SiteUsersReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: update site info config about users + tags: + - admin /answer/admin/api/siteinfo/write: get: description: get site interface diff --git a/internal/base/server/http.go b/internal/base/server/http.go index a8132469..55ff1a31 100644 --- a/internal/base/server/http.go +++ b/internal/base/server/http.go @@ -67,7 +67,7 @@ func NewHTTPServer(debug bool, // plugin routes pluginAPIRouter.RegisterUnAuthConnectorRouter(mustUnAuthV1) - pluginAPIRouter.RegisterAuthConnectorRouter(authV1) + pluginAPIRouter.RegisterAuthUserConnectorRouter(authV1) _ = plugin.CallAgent(func(agent plugin.Agent) error { agent.RegisterUnAuthRouter(unAuthV1) diff --git a/internal/controller/plugin_user_center_controller.go b/internal/controller/plugin_user_center_controller.go index 89f29eaf..8c624a2d 100644 --- a/internal/controller/plugin_user_center_controller.go +++ b/internal/controller/plugin_user_center_controller.go @@ -187,6 +187,12 @@ func (uc *UserCenterController) UserCenterUserSettings(ctx *gin.Context) { handler.HandleResponse(ctx, err, resp) } +// UserCenterAdminFunctionAgent user center admin function agent +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 diff --git a/internal/controller_admin/siteinfo_controller.go b/internal/controller_admin/siteinfo_controller.go index 5e8975d8..04202864 100644 --- a/internal/controller_admin/siteinfo_controller.go +++ b/internal/controller_admin/siteinfo_controller.go @@ -355,7 +355,7 @@ func (sc *SiteInfoController) SaveSiteTheme(ctx *gin.Context) { // @Security ApiKeyAuth // @Tags admin // @Produce json -// @Param data body schema.SiteBrandingReq true "users info" +// @Param data body schema.SiteUsersReq true "users info" // @Success 200 {object} handler.RespBody{} // @Router /answer/admin/api/siteinfo/users [put] func (sc *SiteInfoController) UpdateSiteUsers(ctx *gin.Context) { diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go index 904e34b1..369d015a 100644 --- a/internal/router/answer_api_router.go +++ b/internal/router/answer_api_router.go @@ -103,7 +103,7 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(r *gin.RouterGroup) // user r.GET("/user/info", a.userController.GetUserInfoByUserID) routerGroup := r.Group("", middleware.BanAPIWhenUserCenterEnabled) - routerGroup.POST("/user/login/email", a.userController.UserEmailLogin) + r.POST("/user/login/email", a.userController.UserEmailLogin) routerGroup.POST("/user/register/email", a.userController.UserRegisterByEmail) routerGroup.GET("/user/register/captcha", a.userController.UserRegisterCaptcha) routerGroup.POST("/user/email/verification", a.userController.UserVerifyEmail) diff --git a/internal/router/plugin_api_router.go b/internal/router/plugin_api_router.go index 46a86528..981b34c1 100644 --- a/internal/router/plugin_api_router.go +++ b/internal/router/plugin_api_router.go @@ -37,10 +37,14 @@ func (pr *PluginAPIRouter) RegisterUnAuthConnectorRouter(r *gin.RouterGroup) { r.GET("/user-center/sign-up/callback", pr.userCenterController.UserCenterSignUpCallback) } -func (pr *PluginAPIRouter) RegisterAuthConnectorRouter(r *gin.RouterGroup) { +func (pr *PluginAPIRouter) RegisterAuthUserConnectorRouter(r *gin.RouterGroup) { connectorController := pr.connectorController r.GET("/connector/user/info", connectorController.ConnectorsUserInfo) r.DELETE("/connector/user/unbinding", connectorController.ExternalLoginUnbinding) r.GET("/user-center/user/settings", pr.userCenterController.UserCenterUserSettings) } + +func (pr *PluginAPIRouter) RegisterAuthAdminConnectorRouter(r *gin.RouterGroup) { + r.GET("/user-center/agent", pr.userCenterController.UserCenterAdminFunctionAgent) +} diff --git a/internal/schema/user_external_login_schema.go b/internal/schema/user_external_login_schema.go index c299855b..54735c3d 100644 --- a/internal/schema/user_external_login_schema.go +++ b/internal/schema/user_external_login_schema.go @@ -67,6 +67,10 @@ type UserCenterUserSettingsResp struct { AccountSettingAgent UserSettingAgent `json:"account_setting_agent"` } +type UserCenterAdminFunctionAgentResp struct { + RoleAgentEnabled bool `json:"role_agent_enabled"` +} + type UserSettingAgent struct { Enabled bool `json:"enabled"` RedirectURL string `json:"redirect_url"` 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 64ca58fd..e7f75664 100644 --- a/internal/service/user_external_login/user_center_login_service.go +++ b/internal/service/user_external_login/user_center_login_service.go @@ -195,6 +195,18 @@ func (us *UserCenterLoginService) UserCenterUserSettings(ctx context.Context, us return resp, nil } +func (us *UserCenterLoginService) UserCenterAdminFunctionAgent(ctx context.Context) ( + resp *schema.UserCenterAdminFunctionAgentResp, err error) { + resp = &schema.UserCenterAdminFunctionAgentResp{} + userCenter, ok := plugin.GetUserCenter() + if !ok { + return + } + desc := userCenter.Description() + resp.RoleAgentEnabled = desc.RoleAgentEnabled + return resp, nil +} + func (us *UserCenterLoginService) UserCenterPersonalBranding(ctx context.Context, username string) ( resp *schema.UserCenterPersonalBranding, err error) { resp = &schema.UserCenterPersonalBranding{ diff --git a/plugin/user_center.go b/plugin/user_center.go index c6c74fa6..66687dc1 100644 --- a/plugin/user_center.go +++ b/plugin/user_center.go @@ -29,6 +29,7 @@ type UserCenterDesc struct { LoginRedirectURL string `json:"login_redirect_url"` SignUpRedirectURL string `json:"sign_up_redirect_url"` RankAgentEnabled bool `json:"rank_agent_enabled"` + RoleAgentEnabled bool `json:"role_agent_enabled"` MustAuthEmailEnabled bool `json:"must_auth_email_enabled"` }