多管理员
This commit is contained in:
parent
7e4784b3c2
commit
7143089dcb
15
README.md
15
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 名
|
||||
```
|
||||
|
@ -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("<script>window.location.href='/'</script>")
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type Config struct {
|
||||
CookieName string // 浏览器 Cookie 名称
|
||||
}
|
||||
GitHub struct {
|
||||
Admin string // 管理员登录名
|
||||
Admin []int64 // 管理员ID列表
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user