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.

fix(plugin): connector use site url to redirect

LinkinStarfe6a53fb6277
diff --git a/docs/docs.go b/docs/docs.go
index ea930eba..25caa935 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -16,6 +16,22 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
+ "/": {
+ "get": {
+ "description": "if config file not exist try to redirect to install page",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "installation"
+ ],
+ "summary": "if config file not exist try to redirect to install page",
+ "responses": {}
+ }
+ },
"/answer/admin/api/answer/page": {
"get": {
"security": [
@@ -2101,6 +2117,52 @@ const docTemplate = `{
}
}
},
+ "/answer/api/v1/connector/binding/email": {
+ "post": {
+ "description": "external login binding user send email",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Plugin"
+ ],
+ "summary": "external login binding user send email",
+ "parameters": [
+ {
+ "description": "external login binding user send email",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.ExternalLoginBindingUserSendEmailReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.ExternalLoginBindingUserSendEmailResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/file": {
"post": {
"security": [
@@ -4231,6 +4293,29 @@ const docTemplate = `{
}
}
},
+ "/answer/api/v1/user/email/notification": {
+ "put": {
+ "description": "unsubscribe email notification",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "User"
+ ],
+ "summary": "unsubscribe email notification",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/user/email/verification": {
"post": {
"description": "UserVerifyEmail",
@@ -5614,6 +5699,35 @@ const docTemplate = `{
}
}
},
+ "schema.ExternalLoginBindingUserSendEmailReq": {
+ "type": "object",
+ "required": [
+ "binding_key",
+ "email"
+ ],
+ "properties": {
+ "binding_key": {
+ "type": "string",
+ "maxLength": 100
+ },
+ "email": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "must": {
+ "description": "If must is true, whatever email if exists, try to bind user.\nIf must is false, when email exist, will only be prompted with a warning.",
+ "type": "boolean"
+ }
+ }
+ },
+ "schema.ExternalLoginBindingUserSendEmailResp": {
+ "type": "object",
+ "properties": {
+ "email_exist_and_must_be_confirmed": {
+ "type": "boolean"
+ }
+ }
+ },
"schema.FollowReq": {
"type": "object",
"required": [
diff --git a/docs/swagger.json b/docs/swagger.json
index 883e57cb..64c85c12 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -4,6 +4,22 @@
"contact": {}
},
"paths": {
+ "/": {
+ "get": {
+ "description": "if config file not exist try to redirect to install page",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "installation"
+ ],
+ "summary": "if config file not exist try to redirect to install page",
+ "responses": {}
+ }
+ },
"/answer/admin/api/answer/page": {
"get": {
"security": [
@@ -2089,6 +2105,52 @@
}
}
},
+ "/answer/api/v1/connector/binding/email": {
+ "post": {
+ "description": "external login binding user send email",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Plugin"
+ ],
+ "summary": "external login binding user send email",
+ "parameters": [
+ {
+ "description": "external login binding user send email",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.ExternalLoginBindingUserSendEmailReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.ExternalLoginBindingUserSendEmailResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/file": {
"post": {
"security": [
@@ -4219,6 +4281,29 @@
}
}
},
+ "/answer/api/v1/user/email/notification": {
+ "put": {
+ "description": "unsubscribe email notification",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "User"
+ ],
+ "summary": "unsubscribe email notification",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/user/email/verification": {
"post": {
"description": "UserVerifyEmail",
@@ -5602,6 +5687,35 @@
}
}
},
+ "schema.ExternalLoginBindingUserSendEmailReq": {
+ "type": "object",
+ "required": [
+ "binding_key",
+ "email"
+ ],
+ "properties": {
+ "binding_key": {
+ "type": "string",
+ "maxLength": 100
+ },
+ "email": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "must": {
+ "description": "If must is true, whatever email if exists, try to bind user.\nIf must is false, when email exist, will only be prompted with a warning.",
+ "type": "boolean"
+ }
+ }
+ },
+ "schema.ExternalLoginBindingUserSendEmailResp": {
+ "type": "object",
+ "properties": {
+ "email_exist_and_must_be_confirmed": {
+ "type": "boolean"
+ }
+ }
+ },
"schema.FollowReq": {
"type": "object",
"required": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index a5499337..a9e1cf62 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -293,6 +293,28 @@ definitions:
switch:
type: boolean
type: object
+ schema.ExternalLoginBindingUserSendEmailReq:
+ properties:
+ binding_key:
+ maxLength: 100
+ type: string
+ email:
+ maxLength: 512
+ type: string
+ must:
+ description: |-
+ If must is true, whatever email if exists, try to bind user.
+ If must is false, when email exist, will only be prompted with a warning.
+ type: boolean
+ required:
+ - binding_key
+ - email
+ type: object
+ schema.ExternalLoginBindingUserSendEmailResp:
+ properties:
+ email_exist_and_must_be_confirmed:
+ type: boolean
+ type: object
schema.FollowReq:
properties:
is_cancel:
@@ -1886,6 +1908,17 @@ definitions:
info:
contact: {}
paths:
+ /:
+ get:
+ consumes:
+ - application/json
+ description: if config file not exist try to redirect to install page
+ produces:
+ - application/json
+ responses: {}
+ summary: if config file not exist try to redirect to install page
+ tags:
+ - installation
/answer/admin/api/answer/page:
get:
consumes:
@@ -3140,6 +3173,33 @@ paths:
summary: get comment page
tags:
- Comment
+ /answer/api/v1/connector/binding/email:
+ post:
+ consumes:
+ - application/json
+ description: external login binding user send email
+ parameters:
+ - description: external login binding user send email
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.ExternalLoginBindingUserSendEmailReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/handler.RespBody'
+ - properties:
+ data:
+ $ref: '#/definitions/schema.ExternalLoginBindingUserSendEmailResp'
+ type: object
+ summary: external login binding user send email
+ tags:
+ - Plugin
/answer/api/v1/file:
post:
consumes:
@@ -4439,6 +4499,21 @@ paths:
summary: send email to the user email then change their email
tags:
- User
+ /answer/api/v1/user/email/notification:
+ put:
+ consumes:
+ - application/json
+ description: unsubscribe email notification
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ summary: unsubscribe email notification
+ tags:
+ - User
/answer/api/v1/user/email/verification:
post:
consumes:
diff --git a/internal/controller/connector_controller.go b/internal/controller/connector_controller.go
index 8fe673b9..3eeb8776 100644
--- a/internal/controller/connector_controller.go
+++ b/internal/controller/connector_controller.go
@@ -60,6 +60,12 @@ func (cc *ConnectorController) ConnectorLogin(connector plugin.Connector) (fn fu
func (cc *ConnectorController) ConnectorRedirect(connector plugin.Connector) (fn func(ctx *gin.Context)) {
return func(ctx *gin.Context) {
+ siteGeneral, err := cc.siteInfoService.GetSiteGeneral(ctx)
+ if err != nil {
+ log.Errorf("get site info failed: %v", err)
+ ctx.Redirect(http.StatusFound, "/50x")
+ return
+ }
userInfo, err := connector.ConnectorReceiver(ctx)
if err != nil {
log.Errorf("connector received failed: %v", err)
@@ -80,9 +86,11 @@ func (cc *ConnectorController) ConnectorRedirect(connector plugin.Connector) (fn
return
}
if len(resp.AccessToken) > 0 {
- ctx.Redirect(http.StatusFound, fmt.Sprintf("/users/oauth?access_token=%s", resp.AccessToken))
+ ctx.Redirect(http.StatusFound, fmt.Sprintf("%s/users/oauth?access_token=%s",
+ siteGeneral.SiteUrl, resp.AccessToken))
} else {
- ctx.Redirect(http.StatusFound, fmt.Sprintf("/users/confirm-email?binding_key=%s", resp.BindingKey))
+ ctx.Redirect(http.StatusFound, fmt.Sprintf("%s/users/confirm-email?binding_key=%s",
+ siteGeneral.SiteUrl, resp.BindingKey))
}
}
}
@@ -110,6 +118,15 @@ func (cc *ConnectorController) ConnectorsInfo(ctx *gin.Context) {
handler.HandleResponse(ctx, nil, resp)
}
+// ExternalLoginBindingUserSendEmail external login binding user send email
+// @Summary external login binding user send email
+// @Description external login binding user send email
+// @Tags Plugin
+// @Accept json
+// @Produce json
+// @Param data body schema.ExternalLoginBindingUserSendEmailReq true "external login binding user send email"
+// @Success 200 {object} handler.RespBody{data=schema.ExternalLoginBindingUserSendEmailResp}
+// @Router /answer/api/v1/connector/binding/email [post]
func (cc *ConnectorController) ExternalLoginBindingUserSendEmail(ctx *gin.Context) {
req := &schema.ExternalLoginBindingUserSendEmailReq{}
if handler.BindAndCheck(ctx, req) {
diff --git a/ui/build/index.html b/ui/build/index.html
index 740c1d7a..af03c2fe 100644
--- a/ui/build/index.html
+++ b/ui/build/index.html
@@ -1 +1 @@
-<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.554b9f62.js"></script><link href="/static/css/main.401dc3ca.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"><div id="spin-mask" hidden><script>try{document.querySelector("#spin-mask").removeAttribute("hidden")}catch(e){}</script><style>@keyframes _doc-spin{to{transform:rotate(360deg)}}#spin-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:#fff;z-index:9999}#spin-container{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}#spin-container .spinner{box-sizing:border-box;display:inline-block;width:2rem;height:2rem;vertical-align:-.125em;border:.25rem solid currentColor;border-right-color:transparent;color:rgba(108,117,125,.75);border-radius:50%;animation:.75s linear infinite _doc-spin}</style><div id="spin-container"><div class="spinner"></div></div></div></div></body></html>
\ No newline at end of file
+<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.2dcebe98.js"></script><link href="/static/css/main.401dc3ca.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"><div id="spin-mask"><noscript><style>#spin-mask{display:none!important}</style></noscript><style>@keyframes _doc-spin{to{transform:rotate(360deg)}}#spin-mask{position:fixed;top:0;right:0;bottom:0;left:0;background-color:#fff;z-index:9999}#spin-container{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}#spin-container .spinner{box-sizing:border-box;display:inline-block;width:2rem;height:2rem;vertical-align:-.125em;border:.25rem solid currentColor;border-right-color:transparent;color:rgba(108,117,125,.75);border-radius:50%;animation:.75s linear infinite _doc-spin}</style><div id="spin-container"><div class="spinner"></div></div></div></div></body></html>
\ No newline at end of file