Flow display and user login and rate limit bug

This commit is contained in:
刘河
2019-03-26 11:13:07 +08:00
parent 2a5a45a700
commit 7637cd448e
14 changed files with 164 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package controllers
import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/crypt"
"github.com/cnlh/nps/lib/file"
"github.com/cnlh/nps/server"
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
"strconv"
@@ -33,6 +34,14 @@ func (s *BaseController) Prepare() {
s.Redirect("/login/index", 302)
}
}
if s.GetSession("isAdmin") != nil && !s.GetSession("isAdmin").(bool) {
s.Ctx.Input.SetData("client_id", s.GetSession("clientId").(int))
s.Ctx.Input.SetParam("client_id", strconv.Itoa(s.GetSession("clientId").(int)))
s.Data["isAdmin"] = false
s.CheckUserAuth()
} else {
s.Data["isAdmin"] = true
}
}
//加载模板
@@ -128,3 +137,30 @@ func (s *BaseController) SetInfo(name string) {
func (s *BaseController) SetType(name string) {
s.Data["type"] = name
}
func (s *BaseController) CheckUserAuth() {
if s.controllerName == "client" {
s.StopRun()
}
if s.controllerName == "index" {
if id := s.GetIntNoErr("id"); id != 0 {
belong := false
if strings.Contains(s.actionName, "H") {
if v, ok := file.GetCsvDb().Hosts.Load(id); ok {
if v.(*file.Host).Client.Id == s.GetSession("clientId").(int) {
belong = true
}
}
} else {
if v, ok := file.GetCsvDb().Tasks.Load(id); ok {
if v.(*file.Tunnel).Client.Id == s.GetSession("clientId").(int) {
belong = true
}
}
}
if !belong {
s.StopRun()
}
}
}
}