From 7143089dcb13461e4bd5b8416170aefe999dca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=B6=E7=88=B8?= Date: Sun, 22 Mar 2020 22:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++++++++ cmd/dashboard/controller/oauth2.go | 13 +++++++++++-- model/config.go | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce992ba..d9f579a 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,18 @@ C/S 采用 gRPC 通信,客户端通过添加主机生成的单独 Token 上报 - 首次连接:上报基本信息(系统、CPU基本信息),后面管理员可从客户端主动拉取更新。 - 监控上报:每隔 3s 向服务器上报系统信息 + +配置文件参考: + +```yaml +debug: true +github: + admin: + - 用户 ID,看自己 GitHub 头像链接后面那一串数字 + clientid: GitHub Oauth App clientID + clientsecret: client secret +site: + brand: 站点标题 + domain: localhost + cookiename: tulong #Cookie 名 +``` diff --git a/cmd/dashboard/controller/oauth2.go b/cmd/dashboard/controller/oauth2.go index ea4d8d1..45c776c 100644 --- a/cmd/dashboard/controller/oauth2.go +++ b/cmd/dashboard/controller/oauth2.go @@ -66,7 +66,16 @@ func (oa *oauth2controller) callback(c *gin.Context) { }, true) return } - if gu.GetLogin() != dao.Conf.GitHub.Admin { + var isAdmin bool + if gu.GetID() > 0 { + for i := 0; i < len(dao.Conf.GitHub.Admin); i++ { + if gu.GetID() == dao.Conf.GitHub.Admin[i] { + isAdmin = true + break + } + } + } + if !isAdmin { mygin.ShowErrorPage(c, mygin.ErrInfo{ Code: http.StatusBadRequest, Title: "登录失败", @@ -77,7 +86,7 @@ func (oa *oauth2controller) callback(c *gin.Context) { user := model.NewUserFromGitHub(gu) user.IssueNewToken() dao.DB.Save(&user) - c.SetCookie(dao.Conf.Site.CookieName, user.Token, 60*60*24*14, "", "", false, false) + c.SetCookie(dao.Conf.Site.CookieName, user.Token, 60*60*24, "", "", false, false) c.Status(http.StatusOK) c.Writer.WriteString("") } diff --git a/model/config.go b/model/config.go index 6586d59..08c0d72 100644 --- a/model/config.go +++ b/model/config.go @@ -16,7 +16,7 @@ type Config struct { CookieName string // 浏览器 Cookie 名称 } GitHub struct { - Admin string // 管理员登录名 + Admin []int64 // 管理员ID列表 ClientID string ClientSecret string }