From ed7f933aeeac58147e9115076e8e2e0059166528 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Fri, 20 Dec 2019 12:45:37 +0800 Subject: [PATCH] fixed https://github.com/crawlab-team/crawlab/issues/346 --- backend/conf/config.yml | 4 +++- backend/main.go | 10 ++++---- backend/routes/setting.go | 33 +++++++++++++++++++++++++++ backend/routes/version.go | 17 -------------- frontend/src/App.vue | 7 ++++++ frontend/src/store/index.js | 2 ++ frontend/src/store/modules/setting.js | 28 +++++++++++++++++++++++ frontend/src/views/login/index.vue | 5 +++- 8 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 backend/routes/setting.go delete mode 100644 backend/routes/version.go create mode 100644 frontend/src/store/modules/setting.js diff --git a/backend/conf/config.yml b/backend/conf/config.yml index 9ff0fa31..a6522ba5 100644 --- a/backend/conf/config.yml +++ b/backend/conf/config.yml @@ -32,4 +32,6 @@ task: workers: 4 other: tmppath: "/tmp" -version: 0.4.1 \ No newline at end of file +version: 0.4.1 +setting: + allowRegister: "N" \ No newline at end of file diff --git a/backend/main.go b/backend/main.go index ace026cc..d14f64b7 100644 --- a/backend/main.go +++ b/backend/main.go @@ -114,9 +114,9 @@ func main() { app.Use(middlewares.CORSMiddleware()) anonymousGroup := app.Group("/") { - anonymousGroup.POST("/login", routes.Login) // 用户登录 - anonymousGroup.PUT("/users", routes.PutUser) // 添加用户 - + anonymousGroup.POST("/login", routes.Login) // 用户登录 + anonymousGroup.PUT("/users", routes.PutUser) // 添加用户 + anonymousGroup.GET("/setting", routes.GetSetting) // 获取配置信息 } authGroup := app.Group("/", middlewares.AuthorizationMiddleware()) { @@ -176,8 +176,8 @@ func main() { authGroup.POST("/users/:id", routes.PostUser) // 更改用户 authGroup.DELETE("/users/:id", routes.DeleteUser) // 删除用户 authGroup.GET("/me", routes.GetMe) // 获取自己账户 - //release版本 - authGroup.GET("/version", routes.GetVersion) //获取发布的版本 + // release版本 + authGroup.GET("/version", routes.GetVersion) // 获取发布的版本 } } diff --git a/backend/routes/setting.go b/backend/routes/setting.go new file mode 100644 index 00000000..4429873e --- /dev/null +++ b/backend/routes/setting.go @@ -0,0 +1,33 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + "github.com/spf13/viper" + "net/http" +) + +type SettingBody struct { + AllowRegister string `json:"allow_register"` +} + +func GetVersion(c *gin.Context) { + version := viper.GetString("version") + + c.JSON(http.StatusOK, Response{ + Status: "ok", + Message: "success", + Data: version, + }) +} + +func GetSetting(c *gin.Context) { + allowRegister := viper.GetString("setting.allowRegister") + + body := SettingBody{AllowRegister: allowRegister} + + c.JSON(http.StatusOK, Response{ + Status: "ok", + Message: "success", + Data: body, + }) +} diff --git a/backend/routes/version.go b/backend/routes/version.go deleted file mode 100644 index 719732ad..00000000 --- a/backend/routes/version.go +++ /dev/null @@ -1,17 +0,0 @@ -package routes - -import ( - "github.com/gin-gonic/gin" - "github.com/spf13/viper" - "net/http" -) - -func GetVersion(c *gin.Context) { - version := viper.GetString("version") - - c.JSON(http.StatusOK, Response{ - Status: "ok", - Message: "success", - Data: version, - }) -} diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 2a91e61a..a7ba8069 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -6,6 +6,9 @@